IColor.Convert extension method

This commit is contained in:
Jeremy Pritts committed 2022-11-04 16:22:42 -04:00
1 parent dc1ecc5d46
commit a5cfc5cbf7
2 files changed
+21 -5

No files matched your search

+20
View File
@@ -56,5 +56,25 @@
ConversionUtilities.ConvertValue<TSourceArg, TThisArg>(b),
ConversionUtilities.ConvertValue<TSourceArg, TThisArg>(a));
}
[MethodImpl(OptimizationConstants.AggressiveInliningAndOptimization)]
internal static TTarget Convert<TThis, TThisArg, TTarget, TTargetArg>(this TThis color)
where TThisArg : unmanaged
where TTargetArg : unmanaged
where TThis : unmanaged, IColor<TThisArg>
where TTarget : unmanaged, IColor<TTargetArg>
{
if (typeof(TThis) == typeof(TTarget))
{
return Unsafe.As<TThis, TTarget>(ref color);
}
else
{
TTarget destination = default;
color.GetChannels(out TThisArg r, out TThisArg g, out TThisArg b, out TThisArg a);
destination.SetConvertedChannels<TTarget, TTargetArg, TThisArg>(r, g, b, a);
return destination;
}
}
}
}
@@ -600,11 +600,7 @@ namespace AssetRipper.TextureDecoder.Rgb
{
for (int i = 0; i < sourceSpan.Length; i++)
{
TSource source = sourceSpan[i];
TDestination destination = default;
source.GetChannels(out TSourceArg r, out TSourceArg g, out TSourceArg b, out TSourceArg a);
destination.SetConvertedChannels<TDestination, TDestinationArg, TSourceArg>(r, g, b, a);
destinationSpan[i] = destination;
destinationSpan[i] = sourceSpan[i].Convert<TSource, TSourceArg, TDestination, TDestinationArg>();
}
}