Support BGR24 and ARGBFloat

This commit is contained in:
ds5678 2025-11-28 16:46:23 -08:00
parent 76041cc34e
commit 4707fb5a60
5 changed files with 21 additions and 7 deletions

View File

@ -25,11 +25,15 @@ internal static class Pass039_InjectEnumValues
{ "UnityEngine.TextureFormat",
new()
{
("ARGBFloat", 6, ""),
("BGR24", 8, ""),
("DXT3", 11, ""),
} },
{ "UnityEditor.TextureImporterFormat",
new()
{
("ARGBFloat", 6, ""),
("BGR24", 8, ""),
("DXT3", 11, ""),
} },
{ "UnityEngine.MeshTopology",

View File

@ -13,7 +13,7 @@
<PackageReference Include="AssetRipper.Conversions.Crunch" Version="1.0.3" />
<PackageReference Include="AssetRipper.Conversions.FastPng" Version="1.1.0" />
<PackageReference Include="AssetRipper.Conversions.UnityCrunch" Version="1.0.3" />
<PackageReference Include="AssetRipper.TextureDecoder" Version="2.4.0" />
<PackageReference Include="AssetRipper.TextureDecoder" Version="2.5.0" />
<PackageReference Include="AssetRipper.Tpk" Version="1.1.0" />
<PackageReference Include="StbImageWriteSharp" Version="1.16.7" />
</ItemGroup>

View File

@ -130,13 +130,13 @@ public sealed class DirectBitmap<TColor, TChannel> : DirectBitmap
{
if (UseFastBmp)
{
if (typeof(TColor) == typeof(ColorBGRA32))
if (typeof(TColor) == typeof(ColorBGRA<byte>))
{
BmpWriter.WriteBmp(Data, Width, Height * Depth, stream);
}
else
{
RgbConverter.Convert<TColor, TChannel, ColorBGRA32, byte>(Bits, Width, Height * Depth, out byte[] data);
RgbConverter.Convert<TColor, TChannel, ColorBGRA<byte>, byte>(Bits, Width, Height * Depth, out byte[] data);
BmpWriter.WriteBmp(data, Width, Height * Depth, stream);
}
}

View File

@ -199,11 +199,13 @@ public static class TextureConverter
TextureFormat.ARGB4444 => TryConvertToBitmap<ColorARGB16, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.RGB24 => TryConvertToBitmap<ColorRGB<byte>, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.RGBA32 => TryConvertToBitmap<ColorRGBA<byte>, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.ARGB32 => TryConvertToBitmap<ColorARGB32, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.ARGB32 => TryConvertToBitmap<ColorARGB<byte>, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.ARGBFloat => TryConvertToBitmap<ColorARGB<float>, float>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.RGB565 => TryConvertToBitmap<ColorRGB16, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.BGR24 => TryConvertToBitmap<ColorBGR<byte>, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.R16 => TryConvertToBitmap<ColorR<ushort>, ushort>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.RGBA4444 => TryConvertToBitmap<ColorRGBA16, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.BGRA32_14 or TextureFormat.BGRA32_37 => TryConvertToBitmap<ColorBGRA32, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.BGRA32_14 or TextureFormat.BGRA32_37 => TryConvertToBitmap<ColorBGRA<byte>, byte>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.RHalf => TryConvertToBitmap<ColorR<Half>, Half>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.RGHalf => TryConvertToBitmap<ColorRG<Half>, Half>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
TextureFormat.RGBAHalf => TryConvertToBitmap<ColorRGBA<Half>, Half>(textureFormat, width, height, depth, imageSize, version, data, out bitmap),
@ -442,11 +444,17 @@ public static class TextureConverter
return RgbConverter.Convert<ColorRGBA<byte>, byte, TColor, TChannelValue>(inputSpan, width, height, outputSpan);
case TextureFormat.ARGB32:
return RgbConverter.Convert<ColorARGB32, byte, TColor, TChannelValue>(inputSpan, width, height, outputSpan);
return RgbConverter.Convert<ColorARGB<byte>, byte, TColor, TChannelValue>(inputSpan, width, height, outputSpan);
case TextureFormat.ARGBFloat:
return RgbConverter.Convert<ColorARGB<float>, float, TColor, TChannelValue>(inputSpan, width, height, outputSpan);
case TextureFormat.BGR24:
return RgbConverter.Convert<ColorBGR<byte>, byte, TColor, TChannelValue>(inputSpan, width, height, outputSpan);
case TextureFormat.BGRA32_14:
case TextureFormat.BGRA32_37:
return RgbConverter.Convert<ColorBGRA32, byte, TColor, TChannelValue>(inputSpan, width, height, outputSpan);
return RgbConverter.Convert<ColorBGRA<byte>, byte, TColor, TChannelValue>(inputSpan, width, height, outputSpan);
case TextureFormat.R16:
return RgbConverter.Convert<ColorR<ushort>, ushort, TColor, TChannelValue>(inputSpan, width, height, outputSpan);

View File

@ -173,6 +173,7 @@ public static class SwitchSwizzle
TextureFormat.RFloat => new Size(4, 1),
TextureFormat.RGFloat => new Size(2, 1),
TextureFormat.RGBAFloat => new Size(1, 1),
TextureFormat.ARGBFloat => new Size(1, 1),
_ => null,
};
@ -194,6 +195,7 @@ public static class SwitchSwizzle
TextureFormat.RGB48 => TextureFormat.RGBA64,
TextureFormat.RGB24_SIGNED => TextureFormat.RGBA32_SIGNED,
TextureFormat.RGB48_SIGNED => TextureFormat.RGBA64_SIGNED,
TextureFormat.BGR24 => TextureFormat.BGRA32_14,
_ => format
};
}