Skip to content

Commit f3f7b69

Browse files
committed
Color.GetChannelCount
1 parent 6980a32 commit f3f7b69

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

AssetRipper.TextureDecoder.Tests/Formats/Generic/GenericColorTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ internal partial class GenericColorTests<TColor, TChannel> where TColor : unmana
88
[Test]
99
public void CorrectSizeTest()
1010
{
11-
int numChannels = (TColor.HasRedChannel ? 1 : 0) + (TColor.HasGreenChannel ? 1 : 0) + (TColor.HasBlueChannel ? 1 : 0) + (TColor.HasAlphaChannel ? 1 : 0);
12-
Assert.That(Unsafe.SizeOf<TColor>(), Is.EqualTo(numChannels * Unsafe.SizeOf<TChannel>()));
11+
Assert.That(Unsafe.SizeOf<TColor>(), Is.EqualTo(Color.GetChannelCount<TColor>() * Unsafe.SizeOf<TChannel>()));
1312
}
1413

1514
[Test]
@@ -144,4 +143,4 @@ public void MethodsAreSymmetric()
144143
private static TChannel MakeRandomValue() => ColorRandom<TColor, TChannel>.MakeRandomValue();
145144

146145
private static TColor MakeRandomColor() => ColorRandom<TColor, TChannel>.MakeRandomColor();
147-
}
146+
}

AssetRipper.TextureDecoder/Rgb/Color.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ internal static void SetConvertedChannels<TThis, TThisChannel, TSourceChannel>(t
2828
NumericConversion.Convert<TSourceChannel, TThisChannel>(a));
2929
}
3030

31+
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
32+
public static int GetChannelCount<T>() where T : IColorBase
33+
{
34+
return (T.HasRedChannel ? 1 : 0) + (T.HasGreenChannel ? 1 : 0) + (T.HasBlueChannel ? 1 : 0) + (T.HasAlphaChannel ? 1 : 0);
35+
}
36+
3137
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
3238
public static TTarget Convert<TThis, TThisChannel, TTarget, TTargetChannel>(this TThis color)
3339
where TThisChannel : unmanaged

0 commit comments

Comments
 (0)