From 2b80068673213028d889deb22e84b017c90a88dd Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 7 Feb 2017 02:10:13 +0100 Subject: [PATCH] [MethodImpl(MethodImplOptions.AggressiveInlining)] on packedpixel primitives --- src/ImageSharp/Colors/Color.cs | 23 ++++++++++++++++++ src/ImageSharp/Colors/PackedPixel/Alpha8.cs | 13 ++++++++++ src/ImageSharp/Colors/PackedPixel/Argb.cs | 24 +++++++++++++++++++ src/ImageSharp/Colors/PackedPixel/Bgr565.cs | 14 +++++++++++ src/ImageSharp/Colors/PackedPixel/Bgra4444.cs | 13 ++++++++++ src/ImageSharp/Colors/PackedPixel/Bgra5551.cs | 13 ++++++++++ src/ImageSharp/Colors/PackedPixel/Byte4.cs | 14 +++++++++++ .../Colors/PackedPixel/HalfSingle.cs | 13 ++++++++++ .../Colors/PackedPixel/HalfTypeHelper.cs | 2 ++ .../Colors/PackedPixel/HalfVector2.cs | 14 +++++++++++ .../Colors/PackedPixel/HalfVector4.cs | 13 ++++++++++ .../Colors/PackedPixel/NormalizedByte2.cs | 14 +++++++++++ .../Colors/PackedPixel/NormalizedByte4.cs | 13 ++++++++++ .../Colors/PackedPixel/NormalizedShort2.cs | 14 +++++++++++ .../Colors/PackedPixel/NormalizedShort4.cs | 13 ++++++++++ src/ImageSharp/Colors/PackedPixel/Rg32.cs | 14 +++++++++++ .../Colors/PackedPixel/Rgba1010102.cs | 13 ++++++++++ src/ImageSharp/Colors/PackedPixel/Rgba64.cs | 13 ++++++++++ src/ImageSharp/Colors/PackedPixel/Short2.cs | 14 +++++++++++ src/ImageSharp/Colors/PackedPixel/Short4.cs | 13 ++++++++++ 20 files changed, 277 insertions(+) diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color.cs index 036ee14c1..8d6ce954c 100644 --- a/src/ImageSharp/Colors/Color.cs +++ b/src/ImageSharp/Colors/Color.cs @@ -8,6 +8,7 @@ namespace ImageSharp using System; using System.Globalization; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. @@ -138,11 +139,13 @@ namespace ImageSharp /// public byte R { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return (byte)(this.packedValue >> RedShift); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.packedValue = this.packedValue & 0xFFFFFF00 | (uint)value << RedShift; @@ -154,11 +157,13 @@ namespace ImageSharp /// public byte G { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return (byte)(this.packedValue >> GreenShift); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.packedValue = this.packedValue & 0xFFFF00FF | (uint)value << GreenShift; @@ -170,11 +175,13 @@ namespace ImageSharp /// public byte B { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return (byte)(this.packedValue >> BlueShift); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.packedValue = this.packedValue & 0xFF00FFFF | (uint)value << BlueShift; @@ -186,11 +193,13 @@ namespace ImageSharp /// public byte A { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return (byte)(this.packedValue >> AlphaShift); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.packedValue = this.packedValue & 0x00FFFFFF | (uint)value << AlphaShift; @@ -223,6 +232,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Color left, Color right) { return left.packedValue == right.packedValue; @@ -236,6 +246,7 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Color left, Color right) { return left.packedValue != right.packedValue; @@ -257,6 +268,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.packedValue = Pack(x, y, z, w); @@ -273,6 +285,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { bytes[startIndex] = this.R; @@ -281,6 +294,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { bytes[startIndex] = this.R; @@ -290,6 +304,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { bytes[startIndex] = this.B; @@ -298,6 +313,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { bytes[startIndex] = this.B; @@ -307,12 +323,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.packedValue = Pack(ref vector); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes; @@ -325,6 +343,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Color other) { return this.packedValue == other.packedValue; @@ -350,6 +369,7 @@ namespace ImageSharp /// /// The vector containing the values to pack. /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(ref Vector4 vector) { vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One); @@ -366,6 +386,7 @@ namespace ImageSharp /// /// The vector containing the values to pack. /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(ref Vector3 vector) { Vector4 value = new Vector4(vector, 1); @@ -380,6 +401,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(float x, float y, float z, float w) { Vector4 value = new Vector4(x, y, z, w); @@ -394,6 +416,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(byte x, byte y, byte z, byte w) { return (uint)(x << RedShift | y << GreenShift | z << BlueShift | w << AlphaShift); diff --git a/src/ImageSharp/Colors/PackedPixel/Alpha8.cs b/src/ImageSharp/Colors/PackedPixel/Alpha8.cs index 361fe5b9e..95e620df0 100644 --- a/src/ImageSharp/Colors/PackedPixel/Alpha8.cs +++ b/src/ImageSharp/Colors/PackedPixel/Alpha8.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing a single 8 bit normalized W values that is ranging from 0 to 1. @@ -37,6 +38,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Alpha8 left, Alpha8 right) { return left.PackedValue == right.PackedValue; @@ -50,30 +52,35 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Alpha8 left, Alpha8 right) { return left.PackedValue != right.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.W); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4(0, 0, 0, this.PackedValue / 255F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackedValue = w; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { bytes[startIndex] = 0; @@ -82,6 +89,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { bytes[startIndex] = 0; @@ -91,6 +99,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { bytes[startIndex] = 0; @@ -99,6 +108,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { bytes[startIndex] = 0; @@ -122,6 +132,7 @@ namespace ImageSharp /// /// The Alpha8 packed vector to compare. /// True if the packed vectors are equal. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Alpha8 other) { return this.PackedValue == other.PackedValue; @@ -137,6 +148,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -147,6 +159,7 @@ namespace ImageSharp /// /// The float containing the value to pack. /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static byte Pack(float alpha) { return (byte)Math.Round(alpha.Clamp(0, 1) * 255F); diff --git a/src/ImageSharp/Colors/PackedPixel/Argb.cs b/src/ImageSharp/Colors/PackedPixel/Argb.cs index 8ab8e3f43..432011702 100644 --- a/src/ImageSharp/Colors/PackedPixel/Argb.cs +++ b/src/ImageSharp/Colors/PackedPixel/Argb.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255. @@ -113,11 +114,13 @@ namespace ImageSharp /// public byte R { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return (byte)(this.PackedValue >> RedShift); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.PackedValue = this.PackedValue & 0xFF00FFFF | (uint)value << RedShift; @@ -129,11 +132,13 @@ namespace ImageSharp /// public byte G { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return (byte)(this.PackedValue >> GreenShift); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.PackedValue = this.PackedValue & 0xFFFF00FF | (uint)value << GreenShift; @@ -145,11 +150,13 @@ namespace ImageSharp /// public byte B { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return (byte)(this.PackedValue >> BlueShift); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.PackedValue = this.PackedValue & 0xFFFFFF00 | (uint)value << BlueShift; @@ -161,11 +168,13 @@ namespace ImageSharp /// public byte A { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return (byte)(this.PackedValue >> AlphaShift); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] set { this.PackedValue = this.PackedValue & 0x00FFFFFF | (uint)value << AlphaShift; @@ -184,6 +193,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Argb left, Argb right) { return left.PackedValue == right.PackedValue; @@ -197,30 +207,35 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Argb left, Argb right) { return left.PackedValue != right.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(ref vector); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4(this.R, this.G, this.B, this.A) / MaxBytes; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackedValue = Pack(x, y, z, w); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { bytes[startIndex] = this.R; @@ -229,6 +244,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { bytes[startIndex] = this.R; @@ -238,6 +254,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { bytes[startIndex] = this.B; @@ -246,6 +263,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { bytes[startIndex] = this.B; @@ -261,12 +279,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Argb other) { return this.PackedValue == other.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { // ReSharper disable once NonReadonlyMemberInGetHashCode @@ -281,6 +301,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(float x, float y, float z, float w) { var value = new Vector4(x, y, z, w); @@ -295,6 +316,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(byte x, byte y, byte z, byte w) { return (uint)(x << RedShift | y << GreenShift | z << BlueShift | w << AlphaShift); @@ -305,6 +327,7 @@ namespace ImageSharp /// /// The vector containing the values to pack. /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(ref Vector3 vector) { var value = new Vector4(vector, 1); @@ -316,6 +339,7 @@ namespace ImageSharp /// /// The vector containing the values to pack. /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(ref Vector4 vector) { vector = Vector4.Clamp(vector, Vector4.Zero, Vector4.One); diff --git a/src/ImageSharp/Colors/PackedPixel/Bgr565.cs b/src/ImageSharp/Colors/PackedPixel/Bgr565.cs index 1f1ce0a17..19c7f3d14 100644 --- a/src/ImageSharp/Colors/PackedPixel/Bgr565.cs +++ b/src/ImageSharp/Colors/PackedPixel/Bgr565.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x and z components use 5 bits, and the y component uses 6 bits. @@ -46,6 +47,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Bgr565 left, Bgr565 right) { return left.PackedValue == right.PackedValue; @@ -59,6 +61,7 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Bgr565 left, Bgr565 right) { return left.PackedValue != right.PackedValue; @@ -69,6 +72,7 @@ namespace ImageSharp /// The vector components are typically expanded in least to greatest significance order. /// /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector3 ToVector3() { return new Vector3( @@ -78,24 +82,28 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y, vector.Z); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4(this.ToVector3(), 1F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w) / 255F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -105,6 +113,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -115,6 +124,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -124,6 +134,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -140,6 +151,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Bgr565 other) { return this.PackedValue == other.PackedValue; @@ -152,6 +164,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -164,6 +177,7 @@ namespace ImageSharp /// The y-component /// The z-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ushort Pack(float x, float y, float z) { return (ushort)((((int)Math.Round(x.Clamp(0, 1) * 31F) & 0x1F) << 11) | diff --git a/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs b/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs index 1f33cb791..41f7cba04 100644 --- a/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs +++ b/src/ImageSharp/Colors/PackedPixel/Bgra4444.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing unsigned normalized values, ranging from 0 to 1, using 4 bits each for x, y, z, and w. @@ -45,6 +46,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Bgra4444 left, Bgra4444 right) { return left.PackedValue == right.PackedValue; @@ -58,12 +60,14 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Bgra4444 left, Bgra4444 right) { return left.PackedValue != right.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { const float Max = 1 / 15F; @@ -76,18 +80,21 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y, vector.Z, vector.W); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w) / 255F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -97,6 +104,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -107,6 +115,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -116,6 +125,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -132,6 +142,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Bgra4444 other) { return this.PackedValue == other.PackedValue; @@ -144,6 +155,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -157,6 +169,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ushort Pack(float x, float y, float z, float w) { return (ushort)((((int)Math.Round(w.Clamp(0, 1) * 15F) & 0x0F) << 12) | diff --git a/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs b/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs index d0c52068d..800cb0bf1 100644 --- a/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs +++ b/src/ImageSharp/Colors/PackedPixel/Bgra5551.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing unsigned normalized values ranging from 0 to 1. The x , y and z components use 5 bits, and the w component uses 1 bit. @@ -47,6 +48,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Bgra5551 left, Bgra5551 right) { return left.PackedValue == right.PackedValue; @@ -60,12 +62,14 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Bgra5551 left, Bgra5551 right) { return left.PackedValue != right.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4( @@ -76,18 +80,21 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y, vector.Z, vector.W); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w) / 255F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -97,6 +104,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -107,6 +115,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -116,6 +125,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -132,6 +142,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Bgra5551 other) { return this.PackedValue == other.PackedValue; @@ -150,6 +161,7 @@ namespace ImageSharp /// Gets a hash code of the packed vector. /// /// The hash code for the packed vector. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -163,6 +175,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ushort Pack(float x, float y, float z, float w) { return (ushort)( diff --git a/src/ImageSharp/Colors/PackedPixel/Byte4.cs b/src/ImageSharp/Colors/PackedPixel/Byte4.cs index 69c69ecaf..644acc509 100644 --- a/src/ImageSharp/Colors/PackedPixel/Byte4.cs +++ b/src/ImageSharp/Colors/PackedPixel/Byte4.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 8-bit unsigned integer values, ranging from 0 to 255. @@ -48,6 +49,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Byte4 left, Byte4 right) { return left.PackedValue == right.PackedValue; @@ -61,6 +63,7 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Byte4 left, Byte4 right) { return left.PackedValue != right.PackedValue; @@ -70,6 +73,7 @@ namespace ImageSharp /// Sets the packed representation from a Vector4. /// /// The vector to create the packed representation from. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(ref vector); @@ -79,6 +83,7 @@ namespace ImageSharp /// Expands the packed representation into a Vector4. /// /// The expanded vector. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4( @@ -89,12 +94,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w)); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -104,6 +111,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -114,6 +122,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -123,6 +132,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -139,12 +149,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Byte4 other) { return this == other; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -164,12 +176,14 @@ namespace ImageSharp /// /// The vector containing the values to pack. /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(ref Vector4 vector) { const float Max = 255F; const float Min = 0F; // Clamp the value between min and max values + // TODO: Use Vector4.Clamp() here! uint byte4 = (uint)Math.Round(vector.X.Clamp(Min, Max)) & 0xFF; uint byte3 = ((uint)Math.Round(vector.Y.Clamp(Min, Max)) & 0xFF) << 0x8; uint byte2 = ((uint)Math.Round(vector.Z.Clamp(Min, Max)) & 0xFF) << 0x10; diff --git a/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs b/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs index 22e32aa56..29a55095b 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs +++ b/src/ImageSharp/Colors/PackedPixel/HalfSingle.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing a single 16 bit floating point value. @@ -47,6 +48,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(HalfSingle left, HalfSingle right) { return left.PackedValue == right.PackedValue; @@ -64,6 +66,7 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(HalfSingle left, HalfSingle right) { return left.PackedValue != right.PackedValue; @@ -73,30 +76,35 @@ namespace ImageSharp /// Expands the packed representation into a . /// /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public float ToSingle() { return HalfTypeHelper.Unpack(this.PackedValue); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = HalfTypeHelper.Pack(vector.X); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4(this.ToSingle(), 0, 0, 1); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w) / MaxBytes); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -110,6 +118,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -124,6 +133,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -137,6 +147,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -157,6 +168,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(HalfSingle other) { return this.PackedValue == other.PackedValue; @@ -169,6 +181,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); diff --git a/src/ImageSharp/Colors/PackedPixel/HalfTypeHelper.cs b/src/ImageSharp/Colors/PackedPixel/HalfTypeHelper.cs index d6d680ed4..a19b51323 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfTypeHelper.cs +++ b/src/ImageSharp/Colors/PackedPixel/HalfTypeHelper.cs @@ -5,6 +5,7 @@ namespace ImageSharp { + using System.Runtime.CompilerServices; using System.Runtime.InteropServices; /// @@ -17,6 +18,7 @@ namespace ImageSharp /// /// The float to pack /// The + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ushort Pack(float value) { Uif uif = new Uif { F = value }; diff --git a/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs b/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs index 7c17dcea8..02e93b250 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs +++ b/src/ImageSharp/Colors/PackedPixel/HalfVector2.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing two 16-bit floating-point values. @@ -57,6 +58,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(HalfVector2 left, HalfVector2 right) { return left.Equals(right); @@ -74,6 +76,7 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(HalfVector2 left, HalfVector2 right) { return !left.Equals(right); @@ -83,6 +86,7 @@ namespace ImageSharp /// Expands the packed representation into a . /// /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector2 ToVector2() { Vector2 vector; @@ -92,12 +96,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { Vector2 vector = this.ToVector2(); @@ -105,12 +111,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w) / MaxBytes); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -124,6 +132,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -138,6 +147,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -151,6 +161,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -171,6 +182,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -183,6 +195,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(HalfVector2 other) { return this.PackedValue.Equals(other.PackedValue); @@ -194,6 +207,7 @@ namespace ImageSharp /// The x-component /// The y-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(float x, float y) { uint num2 = HalfTypeHelper.Pack(x); diff --git a/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs b/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs index a7f10fc71..38787acea 100644 --- a/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs +++ b/src/ImageSharp/Colors/PackedPixel/HalfVector4.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 16-bit floating-point values. @@ -60,6 +61,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(HalfVector4 left, HalfVector4 right) { return left.Equals(right); @@ -77,18 +79,21 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(HalfVector4 left, HalfVector4 right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(ref vector); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4( @@ -99,12 +104,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w) / MaxBytes); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -118,6 +125,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -132,6 +140,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -145,6 +154,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -165,6 +175,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -177,6 +188,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(HalfVector4 other) { return this.PackedValue.Equals(other.PackedValue); @@ -187,6 +199,7 @@ namespace ImageSharp /// /// The vector containing the values to pack. /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong Pack(ref Vector4 vector) { ulong num4 = HalfTypeHelper.Pack(vector.X); diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs b/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs index f1dae1066..5196cbfaf 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs +++ b/src/ImageSharp/Colors/PackedPixel/NormalizedByte2.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed packed pixel type containing two 8-bit signed normalized values, ranging from −1 to 1. @@ -62,6 +63,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(NormalizedByte2 left, NormalizedByte2 right) { return left.PackedValue == right.PackedValue; @@ -79,6 +81,7 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(NormalizedByte2 left, NormalizedByte2 right) { return left.PackedValue != right.PackedValue; @@ -89,6 +92,7 @@ namespace ImageSharp /// The vector components are typically expanded in least to greatest significance order. /// /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector2 ToVector2() { return new Vector2( @@ -97,18 +101,21 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4(this.ToVector2(), 0F, 1F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { Vector4 vector = new Vector4(x, y, z, w); @@ -120,6 +127,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -135,6 +143,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -151,6 +160,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -166,6 +176,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -188,12 +199,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(NormalizedByte2 other) { return this.PackedValue == other.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -211,6 +224,7 @@ namespace ImageSharp /// The x-component /// The y-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ushort Pack(float x, float y) { int byte2 = ((ushort)Math.Round(x.Clamp(-1F, 1F) * 127F) & 0xFF) << 0; diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs b/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs index 22eba5182..c5de795e2 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs +++ b/src/ImageSharp/Colors/PackedPixel/NormalizedByte4.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 8-bit signed normalized values, ranging from −1 to 1. @@ -64,6 +65,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(NormalizedByte4 left, NormalizedByte4 right) { return left.PackedValue == right.PackedValue; @@ -81,18 +83,21 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(NormalizedByte4 left, NormalizedByte4 right) { return left.PackedValue != right.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y, vector.Z, vector.W); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4( @@ -103,6 +108,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { Vector4 vector = new Vector4(x, y, z, w); @@ -114,6 +120,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -129,6 +136,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -145,6 +153,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -160,6 +169,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -182,12 +192,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(NormalizedByte4 other) { return this.PackedValue == other.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -207,6 +219,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(float x, float y, float z, float w) { uint byte4 = ((uint)Math.Round(x.Clamp(-1F, 1F) * 127F) & 0xFF) << 0; diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs b/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs index 34b2fc320..8e3570047 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs +++ b/src/ImageSharp/Colors/PackedPixel/NormalizedShort2.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing two 16-bit signed normalized values, ranging from −1 to 1. @@ -62,6 +63,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(NormalizedShort2 left, NormalizedShort2 right) { return left.Equals(right); @@ -79,24 +81,28 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(NormalizedShort2 left, NormalizedShort2 right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4(this.ToVector2(), 0, 1); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { Vector4 vector = new Vector4(x, y, z, w); @@ -108,6 +114,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -123,6 +130,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -139,6 +147,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -154,6 +163,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -174,6 +184,7 @@ namespace ImageSharp /// The vector components are typically expanded in least to greatest significance order. /// /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector2 ToVector2() { const float MaxVal = 0x7FFF; @@ -190,12 +201,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(NormalizedShort2 other) { return this.PackedValue.Equals(other.PackedValue); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -213,6 +226,7 @@ namespace ImageSharp /// The x-component /// The y-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(float x, float y) { const float MaxPos = 0x7FFF; diff --git a/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs b/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs index 9742a5f34..81d182cee 100644 --- a/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs +++ b/src/ImageSharp/Colors/PackedPixel/NormalizedShort4.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 16-bit signed normalized values, ranging from −1 to 1. @@ -64,6 +65,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(NormalizedShort4 left, NormalizedShort4 right) { return left.Equals(right); @@ -81,18 +83,21 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(NormalizedShort4 left, NormalizedShort4 right) { return !left.Equals(right); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y, vector.Z, vector.W); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { const float MaxVal = 0x7FFF; @@ -105,6 +110,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { Vector4 vector = new Vector4(x, y, z, w); @@ -116,6 +122,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -131,6 +138,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -147,6 +155,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -162,6 +171,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -184,12 +194,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(NormalizedShort4 other) { return this.PackedValue.Equals(other.PackedValue); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -209,6 +221,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong Pack(float x, float y, float z, float w) { const float MaxPos = 0x7FFF; diff --git a/src/ImageSharp/Colors/PackedPixel/Rg32.cs b/src/ImageSharp/Colors/PackedPixel/Rg32.cs index d885a4470..f7dab68c3 100644 --- a/src/ImageSharp/Colors/PackedPixel/Rg32.cs +++ b/src/ImageSharp/Colors/PackedPixel/Rg32.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing two 16-bit unsigned normalized values ranging from 0 to 1. @@ -47,6 +48,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Rg32 left, Rg32 right) { return left.PackedValue == right.PackedValue; @@ -64,6 +66,7 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Rg32 left, Rg32 right) { return left.PackedValue != right.PackedValue; @@ -74,6 +77,7 @@ namespace ImageSharp /// The vector components are typically expanded in least to greatest significance order. /// /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector2 ToVector2() { return new Vector2( @@ -82,24 +86,28 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4(this.ToVector2(), 0F, 1F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w) / 255F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -110,6 +118,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -121,6 +130,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -131,6 +141,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -148,6 +159,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Rg32 other) { return this.PackedValue == other.PackedValue; @@ -160,6 +172,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -171,6 +184,7 @@ namespace ImageSharp /// The x-component /// The y-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(float x, float y) { return (uint)( diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs b/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs index da7dbe1ee..8c2261028 100644 --- a/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs +++ b/src/ImageSharp/Colors/PackedPixel/Rgba1010102.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed vector type containing unsigned normalized values ranging from 0 to 1. @@ -50,6 +51,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Rgba1010102 left, Rgba1010102 right) { return left.PackedValue == right.PackedValue; @@ -67,12 +69,14 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Rgba1010102 left, Rgba1010102 right) { return left.PackedValue != right.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4( @@ -83,18 +87,21 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y, vector.Z, vector.W); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w) / 255F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -105,6 +112,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -116,6 +124,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -126,6 +135,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -143,6 +153,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Rgba1010102 other) { return this.PackedValue == other.PackedValue; @@ -155,6 +166,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -168,6 +180,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(float x, float y, float z, float w) { return (uint)( diff --git a/src/ImageSharp/Colors/PackedPixel/Rgba64.cs b/src/ImageSharp/Colors/PackedPixel/Rgba64.cs index 64631f1e1..bb2182649 100644 --- a/src/ImageSharp/Colors/PackedPixel/Rgba64.cs +++ b/src/ImageSharp/Colors/PackedPixel/Rgba64.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 16-bit unsigned normalized values ranging from 0 to 1. @@ -49,6 +50,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Rgba64 left, Rgba64 right) { return left.PackedValue == right.PackedValue; @@ -66,12 +68,14 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Rgba64 left, Rgba64 right) { return left.PackedValue != right.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4( @@ -82,18 +86,21 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y, vector.Z, vector.W); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { this.PackFromVector4(new Vector4(x, y, z, w) / 255F); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -104,6 +111,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -115,6 +123,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -125,6 +134,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4() * 255F; @@ -142,6 +152,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Rgba64 other) { return this.PackedValue == other.PackedValue; @@ -154,6 +165,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -167,6 +179,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong Pack(float x, float y, float z, float w) { return (ulong)Math.Round(x.Clamp(0, 1) * 65535F) | diff --git a/src/ImageSharp/Colors/PackedPixel/Short2.cs b/src/ImageSharp/Colors/PackedPixel/Short2.cs index d45a80fcb..6bfc5d40c 100644 --- a/src/ImageSharp/Colors/PackedPixel/Short2.cs +++ b/src/ImageSharp/Colors/PackedPixel/Short2.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing two 16-bit signed integer values. @@ -62,6 +63,7 @@ namespace ImageSharp /// /// True if the parameter is equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Short2 left, Short2 right) { return left.PackedValue == right.PackedValue; @@ -79,24 +81,28 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Short2 left, Short2 right) { return left.PackedValue != right.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4((short)(this.PackedValue & 0xFFFF), (short)(this.PackedValue >> 0x10), 0, 1); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { Vector2 vector = new Vector2(x, y) / 255; @@ -106,6 +112,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector2 vector = this.ToVector2(); @@ -121,6 +128,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector2 vector = this.ToVector2(); @@ -137,6 +145,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector2 vector = this.ToVector2(); @@ -152,6 +161,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector2 vector = this.ToVector2(); @@ -172,6 +182,7 @@ namespace ImageSharp /// The vector components are typically expanded in least to greatest significance order. /// /// The . + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector2 ToVector2() { return new Vector2((short)(this.PackedValue & 0xFFFF), (short)(this.PackedValue >> 0x10)); @@ -184,12 +195,14 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Short2 other) { return this == other; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -207,6 +220,7 @@ namespace ImageSharp /// The x-component /// The y-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Pack(float x, float y) { // Largest two byte positive number 0xFFFF >> 1; diff --git a/src/ImageSharp/Colors/PackedPixel/Short4.cs b/src/ImageSharp/Colors/PackedPixel/Short4.cs index cd112a90f..4b1f3c253 100644 --- a/src/ImageSharp/Colors/PackedPixel/Short4.cs +++ b/src/ImageSharp/Colors/PackedPixel/Short4.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Numerics; + using System.Runtime.CompilerServices; /// /// Packed pixel type containing four 16-bit signed integer values. @@ -64,6 +65,7 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Short4 left, Short4 right) { return left.PackedValue == right.PackedValue; @@ -81,18 +83,21 @@ namespace ImageSharp /// /// True if the parameter is not equal to the parameter; otherwise, false. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Short4 left, Short4 right) { return left.PackedValue != right.PackedValue; } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromVector4(Vector4 vector) { this.PackedValue = Pack(vector.X, vector.Y, vector.Z, vector.W); } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector4 ToVector4() { return new Vector4( @@ -103,6 +108,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PackFromBytes(byte x, byte y, byte z, byte w) { Vector4 vector = new Vector4(x, y, z, w) / 255; @@ -112,6 +118,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -127,6 +134,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToXyzwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -143,6 +151,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -158,6 +167,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ToZyxwBytes(byte[] bytes, int startIndex) { Vector4 vector = this.ToVector4(); @@ -180,6 +190,7 @@ namespace ImageSharp } /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Short4 other) { return this == other; @@ -189,6 +200,7 @@ namespace ImageSharp /// Gets the hash code for the current instance. /// /// Hash code for the instance. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return this.PackedValue.GetHashCode(); @@ -211,6 +223,7 @@ namespace ImageSharp /// The z-component /// The w-component /// The containing the packed values. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong Pack(float x, float y, float z, float w) { // Largest two byte positive number 0xFFFF >> 1;