Skip to content

Commit 619544f

Browse files
Fix Numerics fallback logic for 32 bit
1 parent 6b1e603 commit 619544f

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

src/ImageSharp/Common/Helpers/Numerics.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ public static Vector4 Clamp(Vector4 value, Vector4 min, Vector4 max)
275275
[MethodImpl(MethodImplOptions.AggressiveInlining)]
276276
public static void Clamp(Span<byte> span, byte min, byte max)
277277
{
278-
int reduced = ClampReduce(span, min, max);
278+
Span<byte> remainder = span.Slice(ClampReduce(span, min, max));
279279

280-
if (reduced > 0)
280+
if (remainder.Length > 0)
281281
{
282-
for (int i = reduced; i < span.Length; i++)
282+
for (int i = 0; i < remainder.Length; i++)
283283
{
284-
ref byte v = ref span[i];
284+
ref byte v = ref remainder[i];
285285
v = Clamp(v, min, max);
286286
}
287287
}
@@ -296,13 +296,13 @@ public static void Clamp(Span<byte> span, byte min, byte max)
296296
[MethodImpl(MethodImplOptions.AggressiveInlining)]
297297
public static void Clamp(Span<uint> span, uint min, uint max)
298298
{
299-
int reduced = ClampReduce(span, min, max);
299+
Span<uint> remainder = span.Slice(ClampReduce(span, min, max));
300300

301-
if (reduced > 0)
301+
if (remainder.Length > 0)
302302
{
303-
for (int i = reduced; i < span.Length; i++)
303+
for (int i = 0; i < remainder.Length; i++)
304304
{
305-
ref uint v = ref span[i];
305+
ref uint v = ref remainder[i];
306306
v = Clamp(v, min, max);
307307
}
308308
}
@@ -317,13 +317,13 @@ public static void Clamp(Span<uint> span, uint min, uint max)
317317
[MethodImpl(MethodImplOptions.AggressiveInlining)]
318318
public static void Clamp(Span<int> span, int min, int max)
319319
{
320-
int reduced = ClampReduce(span, min, max);
320+
Span<int> remainder = span.Slice(ClampReduce(span, min, max));
321321

322-
if (reduced > 0)
322+
if (remainder.Length > 0)
323323
{
324-
for (int i = reduced; i < span.Length; i++)
324+
for (int i = 0; i < remainder.Length; i++)
325325
{
326-
ref int v = ref span[i];
326+
ref int v = ref remainder[i];
327327
v = Clamp(v, min, max);
328328
}
329329
}
@@ -338,13 +338,13 @@ public static void Clamp(Span<int> span, int min, int max)
338338
[MethodImpl(MethodImplOptions.AggressiveInlining)]
339339
public static void Clamp(Span<float> span, float min, float max)
340340
{
341-
int reduced = ClampReduce(span, min, max);
341+
Span<float> remainder = span.Slice(ClampReduce(span, min, max));
342342

343-
if (reduced > 0)
343+
if (remainder.Length > 0)
344344
{
345-
for (int i = reduced; i < span.Length; i++)
345+
for (int i = 0; i < remainder.Length; i++)
346346
{
347-
ref float v = ref span[i];
347+
ref float v = ref remainder[i];
348348
v = Clamp(v, min, max);
349349
}
350350
}
@@ -359,13 +359,13 @@ public static void Clamp(Span<float> span, float min, float max)
359359
[MethodImpl(MethodImplOptions.AggressiveInlining)]
360360
public static void Clamp(Span<double> span, double min, double max)
361361
{
362-
int reduced = ClampReduce(span, min, max);
362+
Span<double> remainder = span.Slice(ClampReduce(span, min, max));
363363

364-
if (reduced > 0)
364+
if (remainder.Length > 0)
365365
{
366-
for (int i = reduced; i < span.Length; i++)
366+
for (int i = 0; i < remainder.Length; i++)
367367
{
368-
ref double v = ref span[i];
368+
ref double v = ref remainder[i];
369369
v = Clamp(v, min, max);
370370
}
371371
}

0 commit comments

Comments
 (0)