Skip to content

Commit 2c2f948

Browse files
committed
Refactor coordinate handling in PvrtcDecoder
Replaced `#define ASSUME_IMAGE_TILING` with a runtime parameter to control coordinate wrapping or clamping behavior. Renamed `LimitCoord` to `LimitCoordinate` for clarity and added an optional `assumeImageTiling` parameter. Updated all method calls to reflect the new name and behavior. Removed inline and optimization attributes from `LimitCoordinate`. Improved method documentation for better readability.
1 parent cd60c44 commit 2c2f948

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

AssetRipper.TextureDecoder/Pvrtc/PvrtcDecoder.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define ASSUME_IMAGE_TILING
2-
31
using AssetRipper.TextureDecoder.Rgb;
42
using System.Diagnostics;
53

@@ -94,12 +92,12 @@ public static int DecompressPVRTC<TOutputColor, TOutputChannelValue>(ReadOnlySpa
9492
int blockX = (x - xBlockSize / 2);
9593
int blockY = (y - BlockYSize / 2);
9694

97-
blockX = LimitCoord(blockX, xDim) / xBlockSize;
98-
blockY = LimitCoord(blockY, yDim) / BlockYSize;
95+
blockX = LimitCoordinate(blockX, xDim) / xBlockSize;
96+
blockY = LimitCoordinate(blockY, yDim) / BlockYSize;
9997

10098
// compute the positions of the other 3 blocks
101-
int blockXp1 = LimitCoord(blockX + 1, blockXDim);
102-
int blockYp1 = LimitCoord(blockY + 1, blockYDim);
99+
int blockXp1 = LimitCoordinate(blockX + 1, blockXDim);
100+
int blockYp1 = LimitCoordinate(blockY + 1, blockYDim);
103101

104102
// map to block memory locations
105103
uint blocki00 = TwiddleUV((uint)blockYDim, (uint)blockXDim, (uint)blockY, (uint)blockX);
@@ -456,19 +454,20 @@ private static void Unpack5554Colour(AmtcBlock block, Span<int> abColors)
456454
}
457455

458456
/// <summary>
459-
/// Define an expression to either wrap or clamp large or small vals to the legal coordinate range
457+
/// Define an expression to either wrap or clamp large or small values to the legal coordinate range.
460458
/// </summary>
461-
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
462-
private static int LimitCoord(int value, int size)
459+
private static int LimitCoordinate(int value, int size, bool assumeImageTiling = true)
463460
{
464-
#if ASSUME_IMAGE_TILING
465-
// wrap coord
466-
return value & (size - 1);
467-
#else
468-
// clamp
469-
return h < x ? h : (x > l ? x : l);
470-
return Clamp(Val, 0, Size - 1);
471-
#endif
461+
if (assumeImageTiling)
462+
{
463+
// wrap coordinate
464+
return value & (size - 1);
465+
}
466+
else
467+
{
468+
// clamp coordinate
469+
return int.Clamp(value, 0, size - 1);
470+
}
472471
}
473472

474473
/// <summary>

0 commit comments

Comments
 (0)