More fixes for BC7 compression speed

This commit is contained in:
KillzXGaming 2019-05-20 18:48:49 -04:00
parent 1b510a05e7
commit 02de27faad
14 changed files with 19 additions and 27 deletions

Binary file not shown.

View file

@ -42,7 +42,7 @@ namespace Bfres.Structs
TEX_FORMAT.R10G10B10A2_UNORM,
TEX_FORMAT.R16_UNORM,
TEX_FORMAT.B4G4R4A4_UNORM,
TEX_FORMAT.B5_G5_R5_A1_UNORM,
TEX_FORMAT.B5G5R5A1_UNORM,
TEX_FORMAT.R8G8B8A8_UNORM_SRGB,
TEX_FORMAT.R8G8B8A8_UNORM,
TEX_FORMAT.R8_UNORM,
@ -566,7 +566,6 @@ namespace Bfres.Structs
case TEX_FORMAT.A8_UNORM: return GX2SurfaceFormat.TC_R8_UNorm;
case TEX_FORMAT.B8G8R8A8_UNORM: return GX2SurfaceFormat.TCS_R8_G8_B8_A8_UNorm;
case TEX_FORMAT.B8G8R8A8_UNORM_SRGB: return GX2SurfaceFormat.TCS_R8_G8_B8_A8_SRGB;
case TEX_FORMAT.B5_G5_R5_A1_UNORM: return GX2SurfaceFormat.TC_A1_B5_G5_R5_UNorm;
case TEX_FORMAT.R32G8X24_FLOAT: return GX2SurfaceFormat.T_R32_Float_X8_X24;
default:
throw new Exception($"Cannot convert format {texFormat}");

View file

@ -704,7 +704,7 @@ namespace FirstPlugin
TEX_FORMAT.B5G6R5_UNORM,
TEX_FORMAT.B8G8R8A8_UNORM_SRGB,
TEX_FORMAT.B8G8R8A8_UNORM,
TEX_FORMAT.B5_G5_R5_A1_UNORM,
TEX_FORMAT.B5G5R5A1_UNORM,
TEX_FORMAT.R8G8B8A8_UNORM_SRGB,
TEX_FORMAT.R8G8B8A8_UNORM,
TEX_FORMAT.R8_UNORM,

View file

@ -408,7 +408,6 @@ namespace FirstPlugin
TEX_FORMAT.R10G10B10A2_UNORM,
TEX_FORMAT.R16_UNORM,
TEX_FORMAT.B4G4R4A4_UNORM,
TEX_FORMAT.B5_G5_R5_A1_UNORM,
TEX_FORMAT.R8G8B8A8_UNORM_SRGB,
TEX_FORMAT.R8G8B8A8_UNORM,
TEX_FORMAT.R8_UNORM,

View file

@ -311,7 +311,7 @@ namespace FirstPlugin
importer.LoadSettings(settings);
if (importer.ShowDialog() == DialogResult.OK)
{
ImportTexture(settings);
ImportTexture(settings, importer.CompressionMode);
}
settings.Clear();
GC.Collect();
@ -335,14 +335,14 @@ namespace FirstPlugin
importer.LoadSettings(settings);
if (importer.ShowDialog() == DialogResult.OK)
{
ImportTexture(settings);
ImportTexture(settings, importer.CompressionMode);
}
settings.Clear();
GC.Collect();
Cursor.Current = Cursors.Default;
}
private void ImportTexture(List<TextureImporterSettings> settings)
private void ImportTexture(List<TextureImporterSettings> settings, STCompressionMode CompressionMode)
{
Cursor.Current = Cursors.WaitCursor;
foreach (var setting in settings)
@ -350,7 +350,7 @@ namespace FirstPlugin
if (setting.GenerateMipmaps && !setting.IsFinishedCompressing)
{
setting.DataBlockOutput.Clear();
setting.DataBlockOutput.Add(setting.GenerateMips());
setting.DataBlockOutput.Add(setting.GenerateMips(CompressionMode));
}
if (setting.DataBlockOutput.Count <= 0)
throw new Exception("Data block is empty! Failed to compress!");
@ -734,7 +734,6 @@ namespace FirstPlugin
TEX_FORMAT.R10G10B10A2_UNORM,
TEX_FORMAT.R16_UNORM,
TEX_FORMAT.B4G4R4A4_UNORM,
TEX_FORMAT.B5_G5_R5_A1_UNORM,
TEX_FORMAT.R8G8B8A8_UNORM_SRGB,
TEX_FORMAT.R8G8B8A8_UNORM,
TEX_FORMAT.R8_UNORM,
@ -847,7 +846,6 @@ namespace FirstPlugin
case TEX_FORMAT.R10G10B10A2_UNORM: return SurfaceFormat.R10_G10_B10_A2_UNORM;
case TEX_FORMAT.R16_UNORM: return SurfaceFormat.R16_UNORM;
case TEX_FORMAT.B4G4R4A4_UNORM: return SurfaceFormat.R4_G4_B4_A4_UNORM;
case TEX_FORMAT.B5_G5_R5_A1_UNORM: return SurfaceFormat.R5_G5_B5_A1_UNORM;
case TEX_FORMAT.R8G8B8A8_UNORM_SRGB: return SurfaceFormat.R8_G8_B8_A8_SRGB;
case TEX_FORMAT.R8G8B8A8_UNORM: return SurfaceFormat.R8_G8_B8_A8_UNORM;
case TEX_FORMAT.R8_UNORM: return SurfaceFormat.R8_UNORM;
@ -1068,11 +1066,11 @@ namespace FirstPlugin
break;
case ".dds":
setting.LoadDDS(FileName, null, this);
ApplyImportSettings(setting);
ApplyImportSettings(setting, STCompressionMode.Normal);
break;
case ".astc":
setting.LoadASTC(FileName);
ApplyImportSettings(setting);
ApplyImportSettings(setting, STCompressionMode.Normal);
break;
default:
setting.LoadBitMap(FileName);
@ -1089,19 +1087,19 @@ namespace FirstPlugin
if (importer.ShowDialog() == DialogResult.OK)
{
ApplyImportSettings(setting);
ApplyImportSettings(setting, importer.CompressionMode);
}
break;
}
}
private void ApplyImportSettings(TextureImporterSettings setting)
private void ApplyImportSettings(TextureImporterSettings setting,STCompressionMode CompressionMode)
{
Cursor.Current = Cursors.WaitCursor;
if (setting.GenerateMipmaps && !setting.IsFinishedCompressing)
{
setting.DataBlockOutput.Clear();
setting.DataBlockOutput.Add(setting.GenerateMips());
setting.DataBlockOutput.Add(setting.GenerateMips(CompressionMode));
}
Texture = setting.FromBitMap(setting.DataBlockOutput, setting);

View file

@ -363,7 +363,6 @@ namespace FirstPlugin
TEX_FORMAT.R10G10B10A2_UNORM,
TEX_FORMAT.R16_UNORM,
TEX_FORMAT.B4G4R4A4_UNORM,
TEX_FORMAT.B5_G5_R5_A1_UNORM,
TEX_FORMAT.R8G8B8A8_UNORM_SRGB,
TEX_FORMAT.R8G8B8A8_UNORM,
TEX_FORMAT.R8_UNORM,

View file

@ -144,7 +144,7 @@ namespace FirstPlugin
TEX_FORMAT.R10G10B10A2_UNORM,
TEX_FORMAT.R16_UNORM,
TEX_FORMAT.B4G4R4A4_UNORM,
TEX_FORMAT.B5_G5_R5_A1_UNORM,
TEX_FORMAT.B5G5R5A1_UNORM,
TEX_FORMAT.R8G8B8A8_UNORM_SRGB,
TEX_FORMAT.R8G8B8A8_UNORM,
TEX_FORMAT.R8_UNORM,
@ -212,7 +212,7 @@ namespace FirstPlugin
case 0x0: return TEX_FORMAT.BC1_UNORM;
case 0x1: return TEX_FORMAT.BC2_UNORM;
case 0x2: return TEX_FORMAT.BC3_UNORM;
case 8: return TEX_FORMAT.B5_G5_R5_A1_UNORM;
case 8: return TEX_FORMAT.B5G5R5A1_UNORM;
case 12: return TEX_FORMAT.R16G16B16A16_UNORM;
case 14: return TEX_FORMAT.R8G8B8A8_UNORM;
case 16: return TEX_FORMAT.R8G8B8A8_UNORM;

View file

@ -16,6 +16,8 @@ namespace FirstPlugin
{
public partial class BinaryTextureImporterList : STForm
{
public STCompressionMode CompressionMode = STCompressionMode.Normal;
public int SelectedIndex = -1;
public bool ForceMipCount = false;
@ -83,10 +85,7 @@ namespace FirstPlugin
compressionModeCB.Items.Add("Fast (Lower Qaulity)");
compressionModeCB.Items.Add("Normal (Good Qaulity)");
compressionModeCB.SelectedIndex = 0;
compressionModeCB.Enabled = false;
foreach (SurfaceDim dim in (SurfaceDim[])Enum.GetValues(typeof(SurfaceDim)))
@ -154,7 +153,6 @@ namespace FirstPlugin
Bitmap bitmap = Switch_Toolbox.Library.Imaging.GetLoadingImage();
STCompressionMode CompressionMode = STCompressionMode.Normal;
if (compressionModeCB.SelectedIndex == 0)
CompressionMode = STCompressionMode.Fast;
@ -167,7 +165,7 @@ namespace FirstPlugin
SelectedTexSettings.Compress(CompressionMode);
ToggleOkButton(true);
// SelectedTexSettings.IsFinishedCompressing = true;
// SelectedTexSettings.IsFinishedCompressing = true;
if (SelectedTexSettings.DataBlockOutput.Count > 0) {
if (SelectedTexSettings.Format == SurfaceFormat.BC5_SNORM)

View file

@ -148,13 +148,13 @@ namespace FirstPlugin
}
public byte[] GenerateMips(int SurfaceLevel = 0)
public byte[] GenerateMips(STCompressionMode CompressionMode, int SurfaceLevel = 0)
{
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);
List<byte[]> mipmaps = new List<byte[]>();
mipmaps.Add(STGenericTexture.CompressBlock(DecompressedData[SurfaceLevel],
(int)TexWidth, (int)TexHeight, TextureData.ConvertFormat(Format), alphaRef));
(int)TexWidth, (int)TexHeight, TextureData.ConvertFormat(Format), alphaRef, CompressionMode));
//while (Image.Width / 2 > 0 && Image.Height / 2 > 0)
// for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
@ -169,7 +169,7 @@ namespace FirstPlugin
Image = BitmapExtension.Resize(Image, width, height);
mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef));
Image.Width, Image.Height, TextureData.ConvertFormat(Format), alphaRef, CompressionMode));
}
Image.Dispose();

View file

@ -157,7 +157,6 @@ namespace Switch_Toolbox.Library
ASTC_12x10_SRGB = 183,
ASTC_12x12_UNORM = 186,
ASTC_12x12_SRGB = 187,
B5_G5_R5_A1_UNORM = 229,
ETC1 = 230,
ETC1_A4 = 231,