Fix bntx and switch bfres causing corruption or crashes
This commit is contained in:
parent
82d68152f9
commit
49314b2842
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -419,7 +419,7 @@ namespace Bfres.Structs
|
||||
try
|
||||
{
|
||||
//Create image block from bitmap first
|
||||
var data = GenerateMipsAndCompress(bitmap, Format);
|
||||
var data = GenerateMipsAndCompress(bitmap, MipCount, Format);
|
||||
|
||||
//Swizzle and create surface
|
||||
var surface = GX2.CreateGx2Texture(data, Text,
|
||||
|
@ -358,7 +358,7 @@ namespace FirstPlugin
|
||||
try
|
||||
{
|
||||
//Create image block from bitmap first
|
||||
var data = GenerateMipsAndCompress(bitmap, Format);
|
||||
var data = GenerateMipsAndCompress(bitmap, MipCount, Format);
|
||||
|
||||
//Swizzle and create surface
|
||||
var surface = GX2.CreateGx2Texture(data, Text,
|
||||
|
@ -377,7 +377,7 @@ namespace FirstPlugin
|
||||
try
|
||||
{
|
||||
//Create image block from bitmap first
|
||||
var data = GenerateMipsAndCompress(bitmap, Format);
|
||||
var data = GenerateMipsAndCompress(bitmap, MipCount, Format);
|
||||
|
||||
//Swizzle and create surface
|
||||
/* var surface = GX2.CreateGx2Texture(data, Text,
|
||||
|
@ -434,7 +434,7 @@ namespace FirstPlugin
|
||||
try
|
||||
{
|
||||
//Create image block from bitmap first
|
||||
var data = GenerateMipsAndCompress(bitmap, Format);
|
||||
var data = GenerateMipsAndCompress(bitmap, MipCount, Format);
|
||||
|
||||
//Swizzle and create surface
|
||||
var surface = GX2.CreateGx2Texture(data, Text,
|
||||
|
@ -347,11 +347,13 @@ namespace FirstPlugin
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
foreach (var setting in settings)
|
||||
{
|
||||
if (setting.GenerateMipmaps)
|
||||
if (setting.GenerateMipmaps && !setting.IsFinishedCompressing)
|
||||
{
|
||||
setting.DataBlockOutput.Clear();
|
||||
setting.DataBlockOutput.Add(setting.GenerateMips());
|
||||
}
|
||||
if (setting.DataBlockOutput.Count <= 0)
|
||||
throw new Exception("Data block is empty! Failed to compress!");
|
||||
|
||||
if (setting.DataBlockOutput != null)
|
||||
{
|
||||
@ -1096,7 +1098,7 @@ namespace FirstPlugin
|
||||
{
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
if (setting.GenerateMipmaps)
|
||||
if (setting.GenerateMipmaps && !setting.IsFinishedCompressing)
|
||||
{
|
||||
setting.DataBlockOutput.Clear();
|
||||
setting.DataBlockOutput.Add(setting.GenerateMips());
|
||||
@ -1193,7 +1195,7 @@ namespace FirstPlugin
|
||||
Texture.TextureData[ArrayLevel].Clear(); //Clear previous mip maps
|
||||
|
||||
var mipmaps = TextureImporterSettings.SwizzleSurfaceMipMaps(Texture,
|
||||
GenerateMipsAndCompress(bitmap, Format), MipCount);
|
||||
GenerateMipsAndCompress(bitmap, MipCount, Format), MipCount);
|
||||
|
||||
Texture.TextureData[ArrayLevel] = mipmaps;
|
||||
|
||||
|
@ -463,7 +463,7 @@ namespace FirstPlugin
|
||||
try
|
||||
{
|
||||
//Create image block from bitmap first
|
||||
var data = GenerateMipsAndCompress(bitmap, Format);
|
||||
var data = GenerateMipsAndCompress(bitmap, MipCount, Format);
|
||||
|
||||
//Swizzle and create surface
|
||||
var NewSurface = GX2.CreateGx2Texture(data, Text,
|
||||
|
@ -540,7 +540,7 @@ namespace FirstPlugin
|
||||
if (!IsSwizzled)
|
||||
{
|
||||
MipCount = GenerateMipCount(bitmap.Width, bitmap.Height);
|
||||
ImageData = GenerateMipsAndCompress(bitmap, Format);
|
||||
ImageData = GenerateMipsAndCompress(bitmap, MipCount, Format);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -577,7 +577,7 @@ namespace FirstPlugin
|
||||
tex.MipOffsets = new long[tex.MipCount];
|
||||
|
||||
var mipmaps = TextureImporterSettings.SwizzleSurfaceMipMaps(tex,
|
||||
GenerateMipsAndCompress(bitmap, Format), MipCount);
|
||||
GenerateMipsAndCompress(bitmap, MipCount, Format), MipCount);
|
||||
|
||||
ImageData = Utils.CombineByteArray(mipmaps.ToArray());
|
||||
}
|
||||
|
@ -568,7 +568,7 @@ namespace FirstPlugin
|
||||
tex.MipOffsets = new long[tex.MipCount];
|
||||
|
||||
var mipmaps = TextureImporterSettings.SwizzleSurfaceMipMaps(tex,
|
||||
GenerateMipsAndCompress(bitmap, Format), MipCount);
|
||||
GenerateMipsAndCompress(bitmap, MipCount, Format), MipCount);
|
||||
|
||||
ImageData = Utils.CombineByteArray(mipmaps.ToArray());
|
||||
}
|
||||
|
@ -160,12 +160,14 @@ namespace FirstPlugin
|
||||
|
||||
Thread = new Thread((ThreadStart)(() =>
|
||||
{
|
||||
SelectedTexSettings.IsFinishedCompressing = false;
|
||||
ToggleOkButton(false);
|
||||
|
||||
pictureBox1.Image = bitmap;
|
||||
SelectedTexSettings.Compress(CompressionMode);
|
||||
|
||||
ToggleOkButton(true);
|
||||
// SelectedTexSettings.IsFinishedCompressing = true;
|
||||
|
||||
if (SelectedTexSettings.DataBlockOutput.Count > 0) {
|
||||
if (SelectedTexSettings.Format == SurfaceFormat.BC5_SNORM)
|
||||
|
@ -51,9 +51,11 @@ namespace FirstPlugin
|
||||
public int sparseResidency = 0; //false
|
||||
public int sparseBinding = 0; //false
|
||||
public bool IsSRGB = true;
|
||||
public bool GenerateMipmaps = false; //If bitmap and count more that 1 then geenrate
|
||||
public bool GenerateMipmaps = false; //If bitmap and count more that 1 then generate
|
||||
public float alphaRef = 0.5f;
|
||||
|
||||
public bool IsFinishedCompressing = false;
|
||||
|
||||
public void LoadDDS(string FileName, byte[] FileData = null, TextureData tree = null)
|
||||
{
|
||||
TexName = STGenericTexture.SetNameFromPath(FileName);
|
||||
|
Binary file not shown.
Binary file not shown.
@ -51,7 +51,7 @@ namespace Switch_Toolbox.Library
|
||||
Height = (uint)Image.Height;
|
||||
MipCount = 1;
|
||||
|
||||
ImageData = GenerateMipsAndCompress(Image, Format);
|
||||
ImageData = GenerateMipsAndCompress(Image, MipCount, Format);
|
||||
|
||||
if (ImageData == null || ImageData.Length <= 0)
|
||||
throw new Exception("Image failed to encode!");
|
||||
|
@ -512,7 +512,7 @@ namespace Switch_Toolbox.Library
|
||||
return MipmapNum;
|
||||
}
|
||||
|
||||
public byte[] GenerateMipsAndCompress(Bitmap bitmap, TEX_FORMAT Format, float alphaRef = 0.5f, STCompressionMode CompressionMode = STCompressionMode.Normal)
|
||||
public static byte[] GenerateMipsAndCompress(Bitmap bitmap, uint MipCount, TEX_FORMAT Format, float alphaRef = 0.5f, STCompressionMode CompressionMode = STCompressionMode.Normal)
|
||||
{
|
||||
byte[] DecompressedData = BitmapExtension.ImageToByte(bitmap);
|
||||
DecompressedData = ConvertBgraToRgba(DecompressedData);
|
||||
@ -520,17 +520,14 @@ namespace Switch_Toolbox.Library
|
||||
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData, bitmap.Width, bitmap.Height);
|
||||
|
||||
List<byte[]> mipmaps = new List<byte[]>();
|
||||
mipmaps.Add(STGenericTexture.CompressBlock(DecompressedData,
|
||||
bitmap.Width, bitmap.Height, Format, alphaRef));
|
||||
|
||||
for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
|
||||
{
|
||||
if (Image.Width / 2 > 0 && Image.Height / 2 > 0)
|
||||
{
|
||||
Image = BitmapExtension.Resize(Image, Image.Width / 2, Image.Height / 2);
|
||||
mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
|
||||
Image.Width, Image.Height, Format, alphaRef, CompressionMode));
|
||||
}
|
||||
int width = Math.Max(1, bitmap.Width >> mipLevel);
|
||||
int height = Math.Max(1, bitmap.Height >> mipLevel);
|
||||
|
||||
Image = BitmapExtension.Resize(Image, width, height);
|
||||
mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
|
||||
Image.Width, Image.Height, Format, alphaRef, CompressionMode));
|
||||
}
|
||||
Image.Dispose();
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user