Browse Source

Tweak grayscale converter code

pull/2922/head
James Jackson-South 1 year ago
parent
commit
e2cde19829
  1. 8
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleScalar.cs
  2. 8
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector128.cs
  3. 8
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector256.cs
  4. 8
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.GrayScaleVector512.cs
  5. 11
      src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbScalar.cs

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

@ -41,11 +41,11 @@ internal abstract partial class JpegColorConverterBase
float scale = 1F / maxValue;
for (nuint i = 0; i < (nuint)values.Component0.Length; i++)
{
ref float c0 = ref Unsafe.Add(ref c0Base, i);
c0 *= scale;
float c = Unsafe.Add(ref c0Base, i) * scale;
Unsafe.Add(ref c1Base, i) = c0;
Unsafe.Add(ref c2Base, i) = c0;
Unsafe.Add(ref c0Base, i) = c;
Unsafe.Add(ref c1Base, i) = c;
Unsafe.Add(ref c2Base, i) = c;
}
}

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

@ -40,11 +40,11 @@ internal abstract partial class JpegColorConverterBase
nuint n = values.Component0.Vector128Count<float>();
for (nuint i = 0; i < n; i++)
{
ref Vector128<float> c0 = ref Unsafe.Add(ref c0Base, i);
c0 *= scale;
Vector128<float> c = Unsafe.Add(ref c0Base, i) * scale;
Unsafe.Add(ref c1Base, i) = c0;
Unsafe.Add(ref c2Base, i) = c0;
Unsafe.Add(ref c0Base, i) = c;
Unsafe.Add(ref c1Base, i) = c;
Unsafe.Add(ref c2Base, i) = c;
}
}

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

@ -36,11 +36,11 @@ internal abstract partial class JpegColorConverterBase
nuint n = values.Component0.Vector256Count<float>();
for (nuint i = 0; i < n; i++)
{
ref Vector256<float> c0 = ref Unsafe.Add(ref c0Base, i);
c0 *= scale;
Vector256<float> c = Unsafe.Add(ref c0Base, i) * scale;
Unsafe.Add(ref c1Base, i) = c0;
Unsafe.Add(ref c2Base, i) = c0;
Unsafe.Add(ref c0Base, i) = c;
Unsafe.Add(ref c1Base, i) = c;
Unsafe.Add(ref c2Base, i) = c;
}
}

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

@ -40,11 +40,11 @@ internal abstract partial class JpegColorConverterBase
nuint n = values.Component0.Vector512Count<float>();
for (nuint i = 0; i < n; i++)
{
ref Vector512<float> c0 = ref Unsafe.Add(ref c0Base, i);
c0 *= scale;
Vector512<float> c = Unsafe.Add(ref c0Base, i) * scale;
Unsafe.Add(ref c1Base, i) = c0;
Unsafe.Add(ref c2Base, i) = c0;
Unsafe.Add(ref c0Base, i) = c;
Unsafe.Add(ref c1Base, i) = c;
Unsafe.Add(ref c2Base, i) = c;
}
}

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

@ -67,14 +67,9 @@ internal abstract partial class JpegColorConverterBase
for (nuint i = 0; i < (nuint)values.Component0.Length; i++)
{
ref float c0 = ref Unsafe.Add(ref c0Base, i);
c0 *= scale;
ref float c1 = ref Unsafe.Add(ref c1Base, i);
c1 *= scale;
ref float c2 = ref Unsafe.Add(ref c2Base, i);
c2 *= scale;
Unsafe.Add(ref c0Base, i) *= scale;
Unsafe.Add(ref c1Base, i) *= scale;
Unsafe.Add(ref c2Base, i) *= scale;
}
}

Loading…
Cancel
Save