mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-16 09:38:05 +00:00
More fixes and try to load depth data
This commit is contained in:
parent
5837fbe5d6
commit
ea099ee2dd
12 changed files with 60 additions and 48 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -360,6 +360,9 @@ namespace FirstPlugin
|
|||
|
||||
public override void OnDoubleMouseClick(TreeView treeView)
|
||||
{
|
||||
if (Data.Length <= 0)
|
||||
return;
|
||||
|
||||
IFileFormat file = STFileLoader.OpenFileFormat(FullName, Data,false, true, this);
|
||||
|
||||
if (Utils.HasInterface(file.GetType(), typeof(IEditor<>)) && !SuppressFormDialog)
|
||||
|
|
|
@ -424,6 +424,9 @@ namespace Bfres.Structs
|
|||
|
||||
var surfaces = GTX.Decode(surf);
|
||||
|
||||
if (ArrayLevel >= surfaces.Count)
|
||||
throw new Exception("Invalid amount of surfaces decoded!");
|
||||
|
||||
return surfaces[ArrayLevel][MipLevel];
|
||||
}
|
||||
|
||||
|
@ -485,6 +488,7 @@ namespace Bfres.Structs
|
|||
case GX2SurfaceFormat.T_R4_G4_UNorm: return TEX_FORMAT.B4G4R4A4_UNORM;
|
||||
case GX2SurfaceFormat.TC_R8_G8_UNorm: return TEX_FORMAT.R8G8_UNORM;
|
||||
case GX2SurfaceFormat.TC_R8_UNorm: return TEX_FORMAT.R8_UNORM;
|
||||
case GX2SurfaceFormat.TC_R16_G16_B16_A16_Float: return TEX_FORMAT.R16G16B16A16_FLOAT;
|
||||
case GX2SurfaceFormat.Invalid: throw new Exception("Invalid Format");
|
||||
default:
|
||||
throw new Exception($"Cannot convert format {GX2Format}");
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace FirstPlugin
|
|||
uint mipSize = 0;
|
||||
uint dataSize = (uint)imageData.Length;
|
||||
uint bpp = GTX.surfaceGetBitsPerPixel((uint)setting.Format) >> 3;
|
||||
int DepthLevel = 1;
|
||||
|
||||
if (dataSize <= 0)
|
||||
throw new Exception($"Image is empty!!");
|
||||
|
@ -95,8 +96,8 @@ namespace FirstPlugin
|
|||
if (mipLevel != 0)
|
||||
mipSize += (uint)(surfOut.surfSize + dataAlignBytes.Length);
|
||||
|
||||
byte[] SwizzledData = GTX.swizzle(width_, height_, surfOut.height, (uint)Format, surfOut.tileMode, s,
|
||||
surfOut.pitch, surfOut.bpp, data_);
|
||||
byte[] SwizzledData = GTX.swizzle(width_, height_, surfOut.depth, surfOut.height, (uint)Format, surfOut.tileMode, s,
|
||||
surfOut.pitch, surfOut.bpp, data_, DepthLevel);
|
||||
|
||||
Swizzled.Add(dataAlignBytes.Concat(SwizzledData).ToArray());
|
||||
}
|
||||
|
|
|
@ -245,8 +245,8 @@ namespace FirstPlugin
|
|||
if (mipLevel != 0)
|
||||
mipSize += (uint)(surfOut.surfSize + dataAlignBytes.Length);
|
||||
|
||||
byte[] SwizzledData = GTX.swizzle(width_, height_, surfOut.height, (uint)Format, surfOut.tileMode, s,
|
||||
surfOut.pitch, surfOut.bpp, data_);
|
||||
byte[] SwizzledData = GTX.swizzle(width_, height_, surfOut.depth, surfOut.height, (uint)Format, surfOut.tileMode, s,
|
||||
surfOut.pitch, surfOut.bpp, data_, 1);
|
||||
|
||||
Swizzled.Add(dataAlignBytes.Concat(SwizzledData).ToArray());
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -487,11 +487,11 @@ namespace Switch_Toolbox.Library
|
|||
if (tex.mipData == null || tex.mipData.Length <= 0)
|
||||
mipCount = 1;
|
||||
|
||||
int ArrayImageize = data.Length / (int)tex.numArray;
|
||||
int ArrayImageize = data.Length / (int)tex.depth;
|
||||
int ArrayMipImageize = 0;
|
||||
|
||||
if (tex.mipData != null)
|
||||
ArrayMipImageize = tex.mipData.Length / (int)tex.numArray;
|
||||
ArrayMipImageize = tex.mipData.Length / (int)tex.depth;
|
||||
|
||||
int dataOffset = 0;
|
||||
int mipDataOffset = 0;
|
||||
|
@ -505,7 +505,7 @@ namespace Switch_Toolbox.Library
|
|||
bool tiling1dLevelSet = false;
|
||||
|
||||
List<List<byte[]>> result = new List<List<byte[]>>();
|
||||
for (int arrayLevel = 0; arrayLevel < tex.numArray; arrayLevel++)
|
||||
for (int arrayLevel = 0; arrayLevel < tex.depth; arrayLevel++)
|
||||
{
|
||||
List<byte[]> mips = new List<byte[]>();
|
||||
for (int mipLevel = 0; mipLevel < mipCount; mipLevel++)
|
||||
|
@ -525,13 +525,13 @@ namespace Switch_Toolbox.Library
|
|||
surfInfo = getSurfaceInfo((GX2SurfaceFormat)tex.format, tex.width, tex.height, tex.depth, (uint)tex.dim, (uint)tex.tileMode, (uint)tex.aa, mipLevel);
|
||||
data = new byte[surfInfo.surfSize];
|
||||
|
||||
Array.Copy(tex.mipData, (uint)mipDataOffset + mipOffset, data, 0, surfInfo.surfSize);
|
||||
Array.Copy(tex.mipData, (uint)mipOffset, data, 0, surfInfo.surfSize);
|
||||
}
|
||||
else
|
||||
Array.Copy(tex.data, (uint)dataOffset, data, 0, size);
|
||||
|
||||
byte[] deswizzled = deswizzle(width_, height_, surfInfo.height, (uint)tex.format,
|
||||
surfInfo.tileMode, (uint)tex.swizzle, surfInfo.pitch, surfInfo.bpp, data);
|
||||
byte[] deswizzled = deswizzle(width_, height_, surfInfo.depth, surfInfo.height, (uint)tex.format,
|
||||
surfInfo.tileMode, (uint)tex.swizzle, surfInfo.pitch, surfInfo.bpp, data, arrayLevel);
|
||||
//Create a copy and use that to remove uneeded data
|
||||
byte[] result_ = new byte[size];
|
||||
Array.Copy(deswizzled, 0, result_, 0, size);
|
||||
|
@ -553,8 +553,6 @@ namespace Switch_Toolbox.Library
|
|||
|
||||
dataOffset += ArrayImageize;
|
||||
mipDataOffset += ArrayMipImageize;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (tiling1dLevelSet)
|
||||
|
@ -573,7 +571,8 @@ namespace Switch_Toolbox.Library
|
|||
return (n + d - 1) / d;
|
||||
}
|
||||
|
||||
private static uint powTwoAlign_0(uint x, uint align) {
|
||||
private static uint powTwoAlign_0(uint x, uint align)
|
||||
{
|
||||
return (x + align - 1) & ~(align - 1);
|
||||
}
|
||||
|
||||
|
@ -604,19 +603,19 @@ namespace Switch_Toolbox.Library
|
|||
}
|
||||
}
|
||||
|
||||
public static byte[] deswizzle(uint width, uint height, uint height_, uint format_, uint tileMode, uint swizzle_,
|
||||
uint pitch, uint bpp, byte[] data)
|
||||
public static byte[] deswizzle(uint width, uint height, uint depth, uint height_, uint format_, uint tileMode, uint swizzle_,
|
||||
uint pitch, uint bpp, byte[] data, int depthLevel)
|
||||
{
|
||||
return swizzleSurf(width, height, height_, format_, tileMode, swizzle_, pitch, bpp, data, 0);
|
||||
return swizzleSurf(width, height, depth, height_, format_, tileMode, swizzle_, pitch, bpp, data, depthLevel, 0);
|
||||
}
|
||||
public static byte[] swizzle(uint width, uint height, uint height_, uint format_, uint tileMode, uint swizzle_,
|
||||
uint pitch, uint bpp, byte[] data)
|
||||
public static byte[] swizzle(uint width, uint height, uint depth, uint height_, uint format_, uint tileMode, uint swizzle_,
|
||||
uint pitch, uint bpp, byte[] data, int depthLevel)
|
||||
{
|
||||
return swizzleSurf(width, height, height_, format_, tileMode, swizzle_, pitch, bpp, data, 1);
|
||||
return swizzleSurf(width, height, depth, height_, format_, tileMode, swizzle_, pitch, bpp, data, depthLevel, 1);
|
||||
}
|
||||
|
||||
private static byte[] swizzleSurf(uint width, uint height, uint height_, uint format, uint tileMode, uint swizzle_,
|
||||
uint pitch, uint bitsPerPixel, byte[] data, int swizzle)
|
||||
private static byte[] swizzleSurf(uint width, uint height,uint depth, uint height_, uint format, uint tileMode, uint swizzle_,
|
||||
uint pitch, uint bitsPerPixel, byte[] data, int depthLevel, int swizzle)
|
||||
{
|
||||
uint bytesPerPixel = bitsPerPixel / 8;
|
||||
byte[] result = new byte[data.Length];
|
||||
|
@ -634,6 +633,11 @@ namespace Switch_Toolbox.Library
|
|||
|
||||
tileMode = GX2TileModeToAddrTileMode(tileMode);
|
||||
|
||||
if (depth > 1)
|
||||
{
|
||||
bankSwizzle = (uint)(depthLevel % 4);
|
||||
}
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
|
|
Loading…
Reference in a new issue