Skip to content

Commit e2cde19

Browse files
Tweak grayscale converter code
1 parent 0e31840 commit e2cde19

File tree

5 files changed

+19
-24
lines changed

5 files changed

+19
-24
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ internal static void ConvertToRgbInPlace(in ComponentValues values, float maxVal
4141
float scale = 1F / maxValue;
4242
for (nuint i = 0; i < (nuint)values.Component0.Length; i++)
4343
{
44-
ref float c0 = ref Unsafe.Add(ref c0Base, i);
45-
c0 *= scale;
44+
float c = Unsafe.Add(ref c0Base, i) * scale;
4645

47-
Unsafe.Add(ref c1Base, i) = c0;
48-
Unsafe.Add(ref c2Base, i) = c0;
46+
Unsafe.Add(ref c0Base, i) = c;
47+
Unsafe.Add(ref c1Base, i) = c;
48+
Unsafe.Add(ref c2Base, i) = c;
4949
}
5050
}
5151

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public override void ConvertToRgbInPlace(in ComponentValues values)
4040
nuint n = values.Component0.Vector128Count<float>();
4141
for (nuint i = 0; i < n; i++)
4242
{
43-
ref Vector128<float> c0 = ref Unsafe.Add(ref c0Base, i);
44-
c0 *= scale;
43+
Vector128<float> c = Unsafe.Add(ref c0Base, i) * scale;
4544

46-
Unsafe.Add(ref c1Base, i) = c0;
47-
Unsafe.Add(ref c2Base, i) = c0;
45+
Unsafe.Add(ref c0Base, i) = c;
46+
Unsafe.Add(ref c1Base, i) = c;
47+
Unsafe.Add(ref c2Base, i) = c;
4848
}
4949
}
5050

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public override void ConvertToRgbInPlace(in ComponentValues values)
3636
nuint n = values.Component0.Vector256Count<float>();
3737
for (nuint i = 0; i < n; i++)
3838
{
39-
ref Vector256<float> c0 = ref Unsafe.Add(ref c0Base, i);
40-
c0 *= scale;
39+
Vector256<float> c = Unsafe.Add(ref c0Base, i) * scale;
4140

42-
Unsafe.Add(ref c1Base, i) = c0;
43-
Unsafe.Add(ref c2Base, i) = c0;
41+
Unsafe.Add(ref c0Base, i) = c;
42+
Unsafe.Add(ref c1Base, i) = c;
43+
Unsafe.Add(ref c2Base, i) = c;
4444
}
4545
}
4646

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ protected override void ConvertToRgbInPlaceVectorized(in ComponentValues values)
4040
nuint n = values.Component0.Vector512Count<float>();
4141
for (nuint i = 0; i < n; i++)
4242
{
43-
ref Vector512<float> c0 = ref Unsafe.Add(ref c0Base, i);
44-
c0 *= scale;
43+
Vector512<float> c = Unsafe.Add(ref c0Base, i) * scale;
4544

46-
Unsafe.Add(ref c1Base, i) = c0;
47-
Unsafe.Add(ref c2Base, i) = c0;
45+
Unsafe.Add(ref c0Base, i) = c;
46+
Unsafe.Add(ref c1Base, i) = c;
47+
Unsafe.Add(ref c2Base, i) = c;
4848
}
4949
}
5050

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,9 @@ internal static void ConvertToRgbInPlace(ComponentValues values, float maxValue)
6767

6868
for (nuint i = 0; i < (nuint)values.Component0.Length; i++)
6969
{
70-
ref float c0 = ref Unsafe.Add(ref c0Base, i);
71-
c0 *= scale;
72-
73-
ref float c1 = ref Unsafe.Add(ref c1Base, i);
74-
c1 *= scale;
75-
76-
ref float c2 = ref Unsafe.Add(ref c2Base, i);
77-
c2 *= scale;
70+
Unsafe.Add(ref c0Base, i) *= scale;
71+
Unsafe.Add(ref c1Base, i) *= scale;
72+
Unsafe.Add(ref c2Base, i) *= scale;
7873
}
7974
}
8075

0 commit comments

Comments
 (0)