Skip to content

Commit 80fee7f

Browse files
Port YccK and use alias
1 parent 87438a3 commit 80fee7f

14 files changed

+551
-79
lines changed

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.CmykVector512.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ protected override void ConvertToRgbInPlaceVectorized(in ComponentValues values)
4848

4949
/// <inheritdoc/>
5050
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
51+
=> ConvertFromRgbVectorized(in values, this.MaximumValue, rLane, gLane, bLane);
52+
53+
/// <inheritdoc/>
54+
protected override void ConvertToRgbInPlaceScalarRemainder(in ComponentValues values)
55+
=> CmykScalar.ConvertToRgbInplace(values, this.MaximumValue);
56+
57+
/// <inheritdoc/>
58+
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
59+
=> CmykScalar.ConvertFromRgb(values, this.MaximumValue, rLane, gLane, bLane);
60+
61+
internal static void ConvertFromRgbVectorized(in ComponentValues values, float maxValue, Span<float> rLane, Span<float> gLane, Span<float> bLane)
5162
{
5263
ref Vector512<float> destC =
5364
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0));
@@ -65,7 +76,7 @@ protected override void ConvertFromRgbVectorized(in ComponentValues values, Span
6576
ref Vector512<float> srcB =
6677
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(bLane));
6778

68-
Vector512<float> scale = Vector512.Create(this.MaximumValue);
79+
Vector512<float> scale = Vector512.Create(maxValue);
6980

7081
nuint n = values.Component0.Vector512Count<float>();
7182
for (nuint i = 0; i < n; i++)
@@ -86,13 +97,5 @@ protected override void ConvertFromRgbVectorized(in ComponentValues values, Span
8697
Unsafe.Add(ref destK, i) = scale - ktmp;
8798
}
8899
}
89-
90-
/// <inheritdoc/>
91-
protected override void ConvertToRgbInPlaceScalarRemainder(in ComponentValues values)
92-
=> CmykScalar.ConvertToRgbInplace(values, this.MaximumValue);
93-
94-
/// <inheritdoc/>
95-
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
96-
=> CmykScalar.ConvertFromRgb(values, this.MaximumValue, rLane, gLane, bLane);
97100
}
98101
}

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector256.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Runtime.CompilerServices;
55
using System.Runtime.InteropServices;
66
using System.Runtime.Intrinsics;
7-
using SixLabors.ImageSharp.Common.Helpers;
7+
using Vector256_ = SixLabors.ImageSharp.Common.Helpers.Vector256Utilities;
88

99
namespace SixLabors.ImageSharp.Formats.Jpeg.Components;
1010

@@ -60,7 +60,7 @@ public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane
6060
ref Vector256<float> b = ref Unsafe.Add(ref srcBlue, i);
6161

6262
// luminosity = (0.299 * r) + (0.587 * g) + (0.114 * b)
63-
Unsafe.Add(ref destLuminance, i) = Vector256Utilities.MultiplyAdd(Vector256Utilities.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
63+
Unsafe.Add(ref destLuminance, i) = Vector256_.MultiplyAdd(Vector256_.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
6464
}
6565
}
6666
}

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector512.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Runtime.CompilerServices;
55
using System.Runtime.InteropServices;
66
using System.Runtime.Intrinsics;
7-
using SixLabors.ImageSharp.Common.Helpers;
7+
using Vector512_ = SixLabors.ImageSharp.Common.Helpers.Vector512Utilities;
88

99
namespace SixLabors.ImageSharp.Formats.Jpeg.Components;
1010

@@ -60,7 +60,7 @@ protected override void ConvertFromRgbVectorized(in ComponentValues values, Span
6060
ref Vector512<float> b = ref Unsafe.Add(ref srcBlue, i);
6161

6262
// luminosity = (0.299 * r) + (0.587 * g) + (0.114 * b)
63-
Unsafe.Add(ref destLuminance, i) = Vector512Utilities.MultiplyAdd(Vector512Utilities.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
63+
Unsafe.Add(ref destLuminance, i) = Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
6464
}
6565
}
6666

@@ -69,7 +69,7 @@ protected override void ConvertToRgbInPlaceScalarRemainder(in ComponentValues va
6969
=> GrayScaleScalar.ConvertToRgbInPlace(values.Component0, this.MaximumValue);
7070

7171
/// <inheritdoc/>
72-
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
73-
=> GrayScaleScalar.ConvertFromRgbScalar(values, r, g, b);
72+
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
73+
=> GrayScaleScalar.ConvertFromRgbScalar(values, rLane, gLane, bLane);
7474
}
7575
}

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector128.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Runtime.CompilerServices;
55
using System.Runtime.InteropServices;
66
using System.Runtime.Intrinsics;
7-
using SixLabors.ImageSharp.Common.Helpers;
7+
using Vector128_ = SixLabors.ImageSharp.Common.Helpers.Vector128Utilities;
88

99
namespace SixLabors.ImageSharp.Formats.Jpeg.Components;
1010

@@ -52,13 +52,13 @@ public override void ConvertToRgbInPlace(in ComponentValues values)
5252
// r = y + (1.402F * cr);
5353
// g = y - (0.344136F * cb) - (0.714136F * cr);
5454
// b = y + (1.772F * cb);
55-
Vector128<float> r = Vector128Utilities.MultiplyAdd(y, cr, rCrMult);
56-
Vector128<float> g = Vector128Utilities.MultiplyAdd(Vector128Utilities.MultiplyAdd(y, cb, gCbMult), cr, gCrMult);
57-
Vector128<float> b = Vector128Utilities.MultiplyAdd(y, cb, bCbMult);
55+
Vector128<float> r = Vector128_.MultiplyAdd(y, cr, rCrMult);
56+
Vector128<float> g = Vector128_.MultiplyAdd(Vector128_.MultiplyAdd(y, cb, gCbMult), cr, gCrMult);
57+
Vector128<float> b = Vector128_.MultiplyAdd(y, cb, bCbMult);
5858

59-
r = Vector128Utilities.RoundToNearestInteger(r) * scale;
60-
g = Vector128Utilities.RoundToNearestInteger(g) * scale;
61-
b = Vector128Utilities.RoundToNearestInteger(b) * scale;
59+
r = Vector128_.RoundToNearestInteger(r) * scale;
60+
g = Vector128_.RoundToNearestInteger(g) * scale;
61+
b = Vector128_.RoundToNearestInteger(b) * scale;
6262

6363
c0 = r;
6464
c1 = g;
@@ -103,9 +103,9 @@ public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane
103103
// y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b)
104104
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
105105
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
106-
Vector128<float> y = Vector128Utilities.MultiplyAdd(Vector128Utilities.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
107-
Vector128<float> cb = chromaOffset + Vector128Utilities.MultiplyAdd(Vector128Utilities.MultiplyAdd(f05 * b, fn0331264, g), fn0168736, r);
108-
Vector128<float> cr = chromaOffset + Vector128Utilities.MultiplyAdd(Vector128Utilities.MultiplyAdd(fn0081312F * b, fn0418688, g), f05, r);
106+
Vector128<float> y = Vector128_.MultiplyAdd(Vector128_.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
107+
Vector128<float> cb = chromaOffset + Vector128_.MultiplyAdd(Vector128_.MultiplyAdd(f05 * b, fn0331264, g), fn0168736, r);
108+
Vector128<float> cr = chromaOffset + Vector128_.MultiplyAdd(Vector128_.MultiplyAdd(fn0081312F * b, fn0418688, g), f05, r);
109109

110110
Unsafe.Add(ref destY, i) = y;
111111
Unsafe.Add(ref destCb, i) = cb;

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector256.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Runtime.CompilerServices;
55
using System.Runtime.InteropServices;
66
using System.Runtime.Intrinsics;
7-
using SixLabors.ImageSharp.Common.Helpers;
7+
using Vector256_ = SixLabors.ImageSharp.Common.Helpers.Vector256Utilities;
88

99
namespace SixLabors.ImageSharp.Formats.Jpeg.Components;
1010

@@ -52,13 +52,13 @@ public override void ConvertToRgbInPlace(in ComponentValues values)
5252
// r = y + (1.402F * cr);
5353
// g = y - (0.344136F * cb) - (0.714136F * cr);
5454
// b = y + (1.772F * cb);
55-
Vector256<float> r = Vector256Utilities.MultiplyAdd(y, cr, rCrMult);
56-
Vector256<float> g = Vector256Utilities.MultiplyAdd(Vector256Utilities.MultiplyAdd(y, cb, gCbMult), cr, gCrMult);
57-
Vector256<float> b = Vector256Utilities.MultiplyAdd(y, cb, bCbMult);
55+
Vector256<float> r = Vector256_.MultiplyAdd(y, cr, rCrMult);
56+
Vector256<float> g = Vector256_.MultiplyAdd(Vector256_.MultiplyAdd(y, cb, gCbMult), cr, gCrMult);
57+
Vector256<float> b = Vector256_.MultiplyAdd(y, cb, bCbMult);
5858

59-
r = Vector256Utilities.RoundToNearestInteger(r) * scale;
60-
g = Vector256Utilities.RoundToNearestInteger(g) * scale;
61-
b = Vector256Utilities.RoundToNearestInteger(b) * scale;
59+
r = Vector256_.RoundToNearestInteger(r) * scale;
60+
g = Vector256_.RoundToNearestInteger(g) * scale;
61+
b = Vector256_.RoundToNearestInteger(b) * scale;
6262

6363
c0 = r;
6464
c1 = g;
@@ -103,9 +103,9 @@ public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane
103103
// y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b)
104104
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
105105
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
106-
Vector256<float> y = Vector256Utilities.MultiplyAdd(Vector256Utilities.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
107-
Vector256<float> cb = chromaOffset + Vector256Utilities.MultiplyAdd(Vector256Utilities.MultiplyAdd(f05 * b, fn0331264, g), fn0168736, r);
108-
Vector256<float> cr = chromaOffset + Vector256Utilities.MultiplyAdd(Vector256Utilities.MultiplyAdd(fn0081312F * b, fn0418688, g), f05, r);
106+
Vector256<float> y = Vector256_.MultiplyAdd(Vector256_.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
107+
Vector256<float> cb = chromaOffset + Vector256_.MultiplyAdd(Vector256_.MultiplyAdd(f05 * b, fn0331264, g), fn0168736, r);
108+
Vector256<float> cr = chromaOffset + Vector256_.MultiplyAdd(Vector256_.MultiplyAdd(fn0081312F * b, fn0418688, g), f05, r);
109109

110110
Unsafe.Add(ref destY, i) = y;
111111
Unsafe.Add(ref destCb, i) = cb;

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YCbCrVector512.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Runtime.CompilerServices;
55
using System.Runtime.InteropServices;
66
using System.Runtime.Intrinsics;
7-
using SixLabors.ImageSharp.Common.Helpers;
7+
using Vector512_ = SixLabors.ImageSharp.Common.Helpers.Vector512Utilities;
88

99
namespace SixLabors.ImageSharp.Formats.Jpeg.Components;
1010

@@ -51,13 +51,13 @@ protected override void ConvertToRgbInPlaceVectorized(in ComponentValues values)
5151
// r = y + (1.402F * cr);
5252
// g = y - (0.344136F * cb) - (0.714136F * cr);
5353
// b = y + (1.772F * cb);
54-
Vector512<float> r = Vector512Utilities.MultiplyAdd(y, cr, rCrMult);
55-
Vector512<float> g = Vector512Utilities.MultiplyAdd(Vector512Utilities.MultiplyAdd(y, cb, gCbMult), cr, gCrMult);
56-
Vector512<float> b = Vector512Utilities.MultiplyAdd(y, cb, bCbMult);
54+
Vector512<float> r = Vector512_.MultiplyAdd(y, cr, rCrMult);
55+
Vector512<float> g = Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(y, cb, gCbMult), cr, gCrMult);
56+
Vector512<float> b = Vector512_.MultiplyAdd(y, cb, bCbMult);
5757

58-
r = Vector512Utilities.RoundToNearestInteger(r) * scale;
59-
g = Vector512Utilities.RoundToNearestInteger(g) * scale;
60-
b = Vector512Utilities.RoundToNearestInteger(b) * scale;
58+
r = Vector512_.RoundToNearestInteger(r) * scale;
59+
g = Vector512_.RoundToNearestInteger(g) * scale;
60+
b = Vector512_.RoundToNearestInteger(b) * scale;
6161

6262
c0 = r;
6363
c1 = g;
@@ -102,9 +102,9 @@ protected override void ConvertFromRgbVectorized(in ComponentValues values, Span
102102
// y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b)
103103
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
104104
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
105-
Vector512<float> y = Vector512Utilities.MultiplyAdd(Vector512Utilities.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
106-
Vector512<float> cb = chromaOffset + Vector512Utilities.MultiplyAdd(Vector512Utilities.MultiplyAdd(f05 * b, fn0331264, g), fn0168736, r);
107-
Vector512<float> cr = chromaOffset + Vector512Utilities.MultiplyAdd(Vector512Utilities.MultiplyAdd(fn0081312F * b, fn0418688, g), f05, r);
105+
Vector512<float> y = Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(f0114 * b, f0587, g), f0299, r);
106+
Vector512<float> cb = chromaOffset + Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(f05 * b, fn0331264, g), fn0168736, r);
107+
Vector512<float> cr = chromaOffset + Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(fn0081312F * b, fn0418688, g), f05, r);
108108

109109
Unsafe.Add(ref destY, i) = y;
110110
Unsafe.Add(ref destCb, i) = cb;

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKScalar.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public YccKScalar(int precision)
2020

2121
/// <inheritdoc/>
2222
public override void ConvertToRgbInPlace(in ComponentValues values)
23-
=> ConvertToRgpInplace(values, this.MaximumValue, this.HalfValue);
23+
=> ConvertToRgpInPlace(values, this.MaximumValue, this.HalfValue);
2424

2525
/// <inheritdoc/>
26-
public override void ConvertFromRgb(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b)
27-
=> ConvertFromRgb(values, this.HalfValue, this.MaximumValue, r, g, b);
26+
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)
27+
=> ConvertFromRgb(values, this.HalfValue, this.MaximumValue, rLane, gLane, bLane);
2828

29-
public static void ConvertToRgpInplace(in ComponentValues values, float maxValue, float halfValue)
29+
public static void ConvertToRgpInPlace(in ComponentValues values, float maxValue, float halfValue)
3030
{
3131
Span<float> c0 = values.Component0;
3232
Span<float> c1 = values.Component1;

src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.YccKVector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override void ConvertToRgbInPlaceVectorized(in ComponentValues values)
7171

7272
/// <inheritdoc/>
7373
protected override void ConvertToRgbInPlaceScalarRemainder(in ComponentValues values)
74-
=> YccKScalar.ConvertToRgpInplace(values, this.MaximumValue, this.HalfValue);
74+
=> YccKScalar.ConvertToRgpInPlace(values, this.MaximumValue, this.HalfValue);
7575

7676
/// <inheritdoc/>
7777
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane)

0 commit comments

Comments
 (0)