Skip to content

Commit b4a5335

Browse files
Add nint optimization
1 parent 8bfd51b commit b4a5335

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ public float this[int idx]
104104
{
105105
GuardBlockIndex(idx);
106106
ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
107-
return Unsafe.Add(ref selfRef, idx);
107+
return Unsafe.Add(ref selfRef, (nint)(uint)idx);
108108
}
109109

110110
[MethodImpl(MethodImplOptions.AggressiveInlining)]
111111
set
112112
{
113113
GuardBlockIndex(idx);
114114
ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
115-
Unsafe.Add(ref selfRef, idx) = value;
115+
Unsafe.Add(ref selfRef, (nint)(uint)idx) = value;
116116
}
117117
}
118118

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private static void CopyToBlock(Span<Rgb24> rgbSpan, ref Block8x8F redBlock, ref
103103

104104
for (int i = 0; i < Block8x8F.Size; i++)
105105
{
106-
Rgb24 c = Unsafe.Add(ref rgbStart, i);
106+
Rgb24 c = Unsafe.Add(ref rgbStart, (nint)(uint)i);
107107

108108
redBlock[i] = c.R;
109109
greenBlock[i] = c.G;

src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,10 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
167167
/// <param name="colorType">The color type.</param>
168168
/// <returns>true, if color type is supported.</returns>
169169
private static bool IsSupportedColorType(JpegColorType? colorType)
170-
{
171-
if (colorType == JpegColorType.YCbCrRatio444 || colorType == JpegColorType.YCbCrRatio420 || colorType == JpegColorType.Luminance || colorType == JpegColorType.Rgb)
172-
{
173-
return true;
174-
}
175-
176-
return false;
177-
}
170+
=> colorType == JpegColorType.YCbCrRatio444
171+
|| colorType == JpegColorType.YCbCrRatio420
172+
|| colorType == JpegColorType.Luminance
173+
|| colorType == JpegColorType.Rgb;
178174

179175
/// <summary>
180176
/// Gets the component ids.

0 commit comments

Comments
 (0)