Browse Source

Add nint optimization

pull/1750/head
James Jackson-South 5 years ago
parent
commit
b4a5335a38
  1. 4
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbForwardConverter{TPixel}.cs
  3. 12
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

4
src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs

@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
GuardBlockIndex(idx);
ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
return Unsafe.Add(ref selfRef, idx);
return Unsafe.Add(ref selfRef, (nint)(uint)idx);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{
GuardBlockIndex(idx);
ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
Unsafe.Add(ref selfRef, idx) = value;
Unsafe.Add(ref selfRef, (nint)(uint)idx) = value;
}
}

2
src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbForwardConverter{TPixel}.cs

@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
for (int i = 0; i < Block8x8F.Size; i++)
{
Rgb24 c = Unsafe.Add(ref rgbStart, i);
Rgb24 c = Unsafe.Add(ref rgbStart, (nint)(uint)i);
redBlock[i] = c.R;
greenBlock[i] = c.G;

12
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

@ -167,14 +167,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <param name="colorType">The color type.</param>
/// <returns>true, if color type is supported.</returns>
private static bool IsSupportedColorType(JpegColorType? colorType)
{
if (colorType == JpegColorType.YCbCrRatio444 || colorType == JpegColorType.YCbCrRatio420 || colorType == JpegColorType.Luminance || colorType == JpegColorType.Rgb)
{
return true;
}
return false;
}
=> colorType == JpegColorType.YCbCrRatio444
|| colorType == JpegColorType.YCbCrRatio420
|| colorType == JpegColorType.Luminance
|| colorType == JpegColorType.Rgb;
/// <summary>
/// Gets the component ids.

Loading…
Cancel
Save