Skip to content

Commit b3371b3

Browse files
committed
Use span for some Astc helper methods
1 parent 05c961f commit b3371b3

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

AssetRipper.TextureDecoder/Astc/AstcDecoder.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
363363
case 0:
364364
fixed (int* endpoint = &pBlock.endpoints[cemOff])
365365
{
366-
SetEndpoint(endpoint, v[0], v[0], v[0], 255, v[1], v[1], v[1], 255);
366+
SetEndpoint(new Span<int>(endpoint, 8), v[0], v[0], v[0], 255, v[1], v[1], v[1], 255);
367367
}
368368
break;
369369
case 1:
@@ -372,14 +372,14 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
372372
int l1 = Clamp(l0 + (v[1] & 0x3f));
373373
fixed (int* endpoint = &pBlock.endpoints[cemOff])
374374
{
375-
SetEndpoint(endpoint, l0, l0, l0, 255, l1, l1, l1, 255);
375+
SetEndpoint(new Span<int>(endpoint, 8), l0, l0, l0, 255, l1, l1, l1, 255);
376376
}
377377
}
378378
break;
379379
case 4:
380380
fixed (int* endpoint = &pBlock.endpoints[cemOff])
381381
{
382-
SetEndpoint(endpoint, v[0], v[0], v[0], v[2], v[1], v[1], v[1], v[3]);
382+
SetEndpoint(new Span<int>(endpoint, 8), v[0], v[0], v[0], v[2], v[1], v[1], v[1], v[3]);
383383
}
384384
break;
385385
case 5:
@@ -388,28 +388,28 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
388388
v[1] += v[0];
389389
fixed (int* endpoint = &pBlock.endpoints[cemOff])
390390
{
391-
SetEndpointClamp(endpoint, v[0], v[0], v[0], v[2], v[1], v[1], v[1], v[2] + v[3]);
391+
SetEndpointClamp(new Span<int>(endpoint, 8), v[0], v[0], v[0], v[2], v[1], v[1], v[1], v[2] + v[3]);
392392
}
393393
break;
394394
case 6:
395395
fixed (int* endpoint = &pBlock.endpoints[cemOff])
396396
{
397-
SetEndpoint(endpoint, v[0] * v[3] >> 8, v[1] * v[3] >> 8, v[2] * v[3] >> 8, 255, v[0], v[1], v[2], 255);
397+
SetEndpoint(new Span<int>(endpoint, 8), v[0] * v[3] >> 8, v[1] * v[3] >> 8, v[2] * v[3] >> 8, 255, v[0], v[1], v[2], 255);
398398
}
399399
break;
400400
case 8:
401401
if (v[0] + v[2] + v[4] <= v[1] + v[3] + v[5])
402402
{
403403
fixed (int* endpoint = &pBlock.endpoints[cemOff])
404404
{
405-
SetEndpoint(endpoint, v[0], v[2], v[4], 255, v[1], v[3], v[5], 255);
405+
SetEndpoint(new Span<int>(endpoint, 8), v[0], v[2], v[4], 255, v[1], v[3], v[5], 255);
406406
}
407407
}
408408
else
409409
{
410410
fixed (int* endpoint = &pBlock.endpoints[cemOff])
411411
{
412-
SetEndpointBlue(endpoint, v[1], v[3], v[5], 255, v[0], v[2], v[4], 255);
412+
SetEndpointBlue(new Span<int>(endpoint, 8), v[1], v[3], v[5], 255, v[0], v[2], v[4], 255);
413413
}
414414
}
415415

@@ -422,37 +422,37 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
422422
{
423423
fixed (int* endpoint = &pBlock.endpoints[cemOff])
424424
{
425-
SetEndpointClamp(endpoint, v[0], v[2], v[4], 255, v[0] + v[1], v[2] + v[3], v[4] + v[5], 255);
425+
SetEndpointClamp(new Span<int>(endpoint, 8), v[0], v[2], v[4], 255, v[0] + v[1], v[2] + v[3], v[4] + v[5], 255);
426426
}
427427
}
428428
else
429429
{
430430
fixed (int* endpoint = &pBlock.endpoints[cemOff])
431431
{
432-
SetEndpointBlueClamp(endpoint, v[0] + v[1], v[2] + v[3], v[4] + v[5], 255, v[0], v[2], v[4], 255);
432+
SetEndpointBlueClamp(new Span<int>(endpoint, 8), v[0] + v[1], v[2] + v[3], v[4] + v[5], 255, v[0], v[2], v[4], 255);
433433
}
434434
}
435435

436436
break;
437437
case 10:
438438
fixed (int* endpoint = &pBlock.endpoints[cemOff])
439439
{
440-
SetEndpoint(endpoint, v[0] * v[3] >> 8, v[1] * v[3] >> 8, v[2] * v[3] >> 8, v[4], v[0], v[1], v[2], v[5]);
440+
SetEndpoint(new Span<int>(endpoint, 8), v[0] * v[3] >> 8, v[1] * v[3] >> 8, v[2] * v[3] >> 8, v[4], v[0], v[1], v[2], v[5]);
441441
}
442442
break;
443443
case 12:
444444
if (v[0] + v[2] + v[4] <= v[1] + v[3] + v[5])
445445
{
446446
fixed (int* endpoint = &pBlock.endpoints[cemOff])
447447
{
448-
SetEndpoint(endpoint, v[0], v[2], v[4], v[6], v[1], v[3], v[5], v[7]);
448+
SetEndpoint(new Span<int>(endpoint, 8), v[0], v[2], v[4], v[6], v[1], v[3], v[5], v[7]);
449449
}
450450
}
451451
else
452452
{
453453
fixed (int* endpoint = &pBlock.endpoints[cemOff])
454454
{
455-
SetEndpointBlue(endpoint, v[1], v[3], v[5], v[7], v[0], v[2], v[4], v[6]);
455+
SetEndpointBlue(new Span<int>(endpoint, 8), v[1], v[3], v[5], v[7], v[0], v[2], v[4], v[6]);
456456
}
457457
}
458458

@@ -466,14 +466,14 @@ private unsafe static void DecodeEndpoints(ReadOnlySpan<byte> input, ref BlockDa
466466
{
467467
fixed (int* endpoint = &pBlock.endpoints[cemOff])
468468
{
469-
SetEndpointClamp(endpoint, v[0], v[2], v[4], v[6], v[0] + v[1], v[2] + v[3], v[4] + v[5], v[6] + v[7]);
469+
SetEndpointClamp(new Span<int>(endpoint, 8), v[0], v[2], v[4], v[6], v[0] + v[1], v[2] + v[3], v[4] + v[5], v[6] + v[7]);
470470
}
471471
}
472472
else
473473
{
474474
fixed (int* endpoint = &pBlock.endpoints[cemOff])
475475
{
476-
SetEndpointBlueClamp(endpoint, v[0] + v[1], v[2] + v[3], v[4] + v[5], v[6] + v[7], v[0], v[2], v[4], v[6]);
476+
SetEndpointBlueClamp(new Span<int>(endpoint, 8), v[0] + v[1], v[2] + v[3], v[4] + v[5], v[6] + v[7], v[0], v[2], v[4], v[6]);
477477
}
478478
}
479479

@@ -914,26 +914,26 @@ private static ulong BitReverseU64(ulong d, int bits)
914914
unchecked
915915
{
916916
ret =
917-
(ulong)BitReverseTable[(int)(d >> 0 & 0xff)] << 56 |
918-
(ulong)BitReverseTable[(int)(d >> 8 & 0xff)] << 48 |
919-
(ulong)BitReverseTable[(int)(d >> 16 & 0xff)] << 40 |
920-
(ulong)BitReverseTable[(int)(d >> 24 & 0xff)] << 32 |
921-
(ulong)BitReverseTable[(int)(d >> 32 & 0xff)] << 24 |
922-
(ulong)BitReverseTable[(int)(d >> 40 & 0xff)] << 16 |
923-
(ulong)BitReverseTable[(int)(d >> 48 & 0xff)] << 8 |
924-
(ulong)BitReverseTable[(int)(d >> 56 & 0xff)];
917+
(ulong)BitReverseTable[(int)(d >> 0 & 0xff)] << 56 |
918+
(ulong)BitReverseTable[(int)(d >> 8 & 0xff)] << 48 |
919+
(ulong)BitReverseTable[(int)(d >> 16 & 0xff)] << 40 |
920+
(ulong)BitReverseTable[(int)(d >> 24 & 0xff)] << 32 |
921+
(ulong)BitReverseTable[(int)(d >> 32 & 0xff)] << 24 |
922+
(ulong)BitReverseTable[(int)(d >> 40 & 0xff)] << 16 |
923+
(ulong)BitReverseTable[(int)(d >> 48 & 0xff)] << 8 |
924+
(ulong)BitReverseTable[(int)(d >> 56 & 0xff)];
925925
}
926926
return ret >> (64 - bits);
927927
}
928928

929929
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
930-
private unsafe static int GetBits(ReadOnlySpan<byte> input, int bit, int len)
930+
private static int GetBits(ReadOnlySpan<byte> input, int bit, int len)
931931
{
932932
return (BinaryPrimitives.ReadInt32LittleEndian(input[(bit / 8)..]) >> (bit % 8)) & ((1 << len) - 1);
933933
}
934934

935935
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
936-
private unsafe static ulong GetBits64(ReadOnlySpan<byte> input, int bit, int len)
936+
private static ulong GetBits64(ReadOnlySpan<byte> input, int bit, int len)
937937
{
938938
ulong mask = len == 64 ? 0xffffffffffffffff : (1UL << len) - 1;
939939
if (len < 1)
@@ -976,7 +976,7 @@ private static unsafe void BitTransferSigned(int* a, int* b)
976976
}
977977

978978
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
979-
private unsafe static void SetEndpoint(int* endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
979+
private static void SetEndpoint(Span<int> endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
980980
{
981981
endpoint[0] = r1;
982982
endpoint[1] = g1;
@@ -989,7 +989,7 @@ private unsafe static void SetEndpoint(int* endpoint, int r1, int g1, int b1, in
989989
}
990990

991991
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
992-
private unsafe static void SetEndpointClamp(int* endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
992+
private static void SetEndpointClamp(Span<int> endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
993993
{
994994
endpoint[0] = Clamp(r1);
995995
endpoint[1] = Clamp(g1);
@@ -1002,7 +1002,7 @@ private unsafe static void SetEndpointClamp(int* endpoint, int r1, int g1, int b
10021002
}
10031003

10041004
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
1005-
private unsafe static void SetEndpointBlue(int* endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
1005+
private static void SetEndpointBlue(Span<int> endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
10061006
{
10071007
endpoint[0] = (r1 + b1) >> 1;
10081008
endpoint[1] = (g1 + b1) >> 1;
@@ -1015,7 +1015,7 @@ private unsafe static void SetEndpointBlue(int* endpoint, int r1, int g1, int b1
10151015
}
10161016

10171017
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
1018-
private unsafe static void SetEndpointBlueClamp(int* endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
1018+
private static void SetEndpointBlueClamp(Span<int> endpoint, int r1, int g1, int b1, int a1, int r2, int g2, int b2, int a2)
10191019
{
10201020
endpoint[0] = Clamp((r1 + b1) >> 1);
10211021
endpoint[1] = Clamp((g1 + b1) >> 1);

0 commit comments

Comments
 (0)