mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 04:23:09 +00:00
Remove some previous decompression methods
This commit is contained in:
parent
5e15f09c6e
commit
2e1d311649
10 changed files with 24 additions and 652 deletions
23
.gitignore
vendored
23
.gitignore
vendored
|
@ -1,5 +1,26 @@
|
|||
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/db.lock
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
*.resources
|
||||
Debug/
|
||||
Release/
|
||||
Release/
|
||||
.vs/Switch_Toolbox/v15/.suo
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide
|
||||
.vs/Switch_Toolbox/v15/.suo
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide
|
||||
.vs/Switch_Toolbox/v15/.suo
|
||||
*.ide
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-shm
|
||||
.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide
|
||||
.vs/Switch_Toolbox/v15/.suo
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -470,9 +470,9 @@ namespace FirstPlugin
|
|||
case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC5_SNORM):
|
||||
decomp = DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true); break;
|
||||
case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_SNORM):
|
||||
decomp = DDS_PixelDecode.DecodeR8G8B8A8(data, (int)Width, (int)Height); break;
|
||||
break;
|
||||
case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_UINT):
|
||||
decomp = DDS_PixelDecode.DecodeR8G8B8A8(data, (int)Width, (int)Height); break;
|
||||
break;
|
||||
default:
|
||||
decomp = Properties.Resources.TextureError;
|
||||
Console.WriteLine($"Format {Format} not supported!");
|
||||
|
|
|
@ -19,51 +19,29 @@ EndProject
|
|||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E861C28B-B039-48F7-9A4F-C83F67C0ADDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E861C28B-B039-48F7-9A4F-C83F67C0ADDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E861C28B-B039-48F7-9A4F-C83F67C0ADDE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E861C28B-B039-48F7-9A4F-C83F67C0ADDE}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{E861C28B-B039-48F7-9A4F-C83F67C0ADDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E861C28B-B039-48F7-9A4F-C83F67C0ADDE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E861C28B-B039-48F7-9A4F-C83F67C0ADDE}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E861C28B-B039-48F7-9A4F-C83F67C0ADDE}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A11705CF-A6A3-41C3-875A-E1CFD8080F09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A11705CF-A6A3-41C3-875A-E1CFD8080F09}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A11705CF-A6A3-41C3-875A-E1CFD8080F09}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A11705CF-A6A3-41C3-875A-E1CFD8080F09}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A11705CF-A6A3-41C3-875A-E1CFD8080F09}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A11705CF-A6A3-41C3-875A-E1CFD8080F09}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A11705CF-A6A3-41C3-875A-E1CFD8080F09}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A11705CF-A6A3-41C3-875A-E1CFD8080F09}.Release|x64.Build.0 = Release|Any CPU
|
||||
{96820047-2A39-4E5A-BFA4-E84FFF5C66CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{96820047-2A39-4E5A-BFA4-E84FFF5C66CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{96820047-2A39-4E5A-BFA4-E84FFF5C66CF}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{96820047-2A39-4E5A-BFA4-E84FFF5C66CF}.Debug|x64.Build.0 = Debug|x64
|
||||
{96820047-2A39-4E5A-BFA4-E84FFF5C66CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{96820047-2A39-4E5A-BFA4-E84FFF5C66CF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{96820047-2A39-4E5A-BFA4-E84FFF5C66CF}.Release|x64.ActiveCfg = Release|x64
|
||||
{96820047-2A39-4E5A-BFA4-E84FFF5C66CF}.Release|x64.Build.0 = Release|x64
|
||||
{29647BA5-2859-46F0-A99E-C3A387A9447A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{29647BA5-2859-46F0-A99E-C3A387A9447A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{29647BA5-2859-46F0-A99E-C3A387A9447A}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{29647BA5-2859-46F0-A99E-C3A387A9447A}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{29647BA5-2859-46F0-A99E-C3A387A9447A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{29647BA5-2859-46F0-A99E-C3A387A9447A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{29647BA5-2859-46F0-A99E-C3A387A9447A}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{29647BA5-2859-46F0-A99E-C3A387A9447A}.Release|x64.Build.0 = Release|Any CPU
|
||||
{D82A2C08-2A65-43AF-BDA6-A36CC27AA003}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D82A2C08-2A65-43AF-BDA6-A36CC27AA003}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D82A2C08-2A65-43AF-BDA6-A36CC27AA003}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{D82A2C08-2A65-43AF-BDA6-A36CC27AA003}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{D82A2C08-2A65-43AF-BDA6-A36CC27AA003}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D82A2C08-2A65-43AF-BDA6-A36CC27AA003}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D82A2C08-2A65-43AF-BDA6-A36CC27AA003}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{D82A2C08-2A65-43AF-BDA6-A36CC27AA003}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -1,542 +0,0 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using Switch_Toolbox.Library;
|
||||
using DirectXTex;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public class DDS_Decompress
|
||||
{
|
||||
//Huge thanks to gdkchan and AbooodXD for the method of decomp BC5/BC4.
|
||||
|
||||
//Todo. Add these to DDS code and add in methods to compress and decode more formats
|
||||
//BC7 also needs to be decompressed properly since OpenTK can't decompress those
|
||||
|
||||
//BC4 actually breaks a bit with artifacts so i'll need to go back and fix
|
||||
|
||||
private static byte[] BCnDecodeTile(byte[] Input, int Offset, bool IsBC1)
|
||||
{
|
||||
Color[] CLUT = new Color[4];
|
||||
|
||||
int c0 = Get16(Input, Offset + 0);
|
||||
int c1 = Get16(Input, Offset + 2);
|
||||
|
||||
CLUT[0] = DecodeRGB565(c0);
|
||||
CLUT[1] = DecodeRGB565(c1);
|
||||
CLUT[2] = CalculateCLUT2(CLUT[0], CLUT[1], c0, c1, IsBC1);
|
||||
CLUT[3] = CalculateCLUT3(CLUT[0], CLUT[1], c0, c1, IsBC1);
|
||||
|
||||
int Indices = Get32(Input, Offset + 4);
|
||||
|
||||
int IdxShift = 0;
|
||||
|
||||
byte[] Output = new byte[4 * 4 * 4];
|
||||
|
||||
int OOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < 4; TY++)
|
||||
{
|
||||
for (int TX = 0; TX < 4; TX++)
|
||||
{
|
||||
int Idx = (Indices >> IdxShift) & 3;
|
||||
|
||||
IdxShift += 2;
|
||||
|
||||
Color Pixel = CLUT[Idx];
|
||||
|
||||
Output[OOffset + 0] = Pixel.B;
|
||||
Output[OOffset + 1] = Pixel.G;
|
||||
Output[OOffset + 2] = Pixel.R;
|
||||
Output[OOffset + 3] = Pixel.A;
|
||||
|
||||
OOffset += 4;
|
||||
}
|
||||
}
|
||||
return Output;
|
||||
}
|
||||
private static Color DecodeRGB565(int Value)
|
||||
{
|
||||
int B = ((Value >> 0) & 0x1f) << 3;
|
||||
int G = ((Value >> 5) & 0x3f) << 2;
|
||||
int R = ((Value >> 11) & 0x1f) << 3;
|
||||
|
||||
return Color.FromArgb(
|
||||
R | (R >> 5),
|
||||
G | (G >> 6),
|
||||
B | (B >> 5));
|
||||
}
|
||||
private static Color CalculateCLUT2(Color C0, Color C1, int c0, int c1, bool IsBC1)
|
||||
{
|
||||
if (c0 > c1 || !IsBC1)
|
||||
{
|
||||
return Color.FromArgb(
|
||||
(2 * C0.R + C1.R) / 3,
|
||||
(2 * C0.G + C1.G) / 3,
|
||||
(2 * C0.B + C1.B) / 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Color.FromArgb(
|
||||
(C0.R + C1.R) / 2,
|
||||
(C0.G + C1.G) / 2,
|
||||
(C0.B + C1.B) / 2);
|
||||
}
|
||||
}
|
||||
private static Color CalculateCLUT3(Color C0, Color C1, int c0, int c1, bool IsBC1)
|
||||
{
|
||||
if (c0 > c1 || !IsBC1)
|
||||
{
|
||||
return
|
||||
Color.FromArgb(
|
||||
(2 * C1.R + C0.R) / 3,
|
||||
(2 * C1.G + C0.G) / 3,
|
||||
(2 * C1.B + C0.B) / 3);
|
||||
}
|
||||
|
||||
return Color.Transparent;
|
||||
}
|
||||
public static Bitmap DecompressBC1(Byte[] data, int width, int height, bool IsSRGB)
|
||||
{
|
||||
int W = (width + 3) / 4;
|
||||
int H = (height + 3) / 4;
|
||||
|
||||
byte[] Output = new byte[W * H * 64];
|
||||
|
||||
for (int Y = 0; Y < H; Y++)
|
||||
{
|
||||
for (int X = 0; X < W; X++)
|
||||
{
|
||||
int IOffs = (Y * W + X) * 8;
|
||||
|
||||
byte[] Tile = BCnDecodeTile(data, IOffs, true);
|
||||
|
||||
int TOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < 4; TY++)
|
||||
{
|
||||
for (int TX = 0; TX < 4; TX++)
|
||||
{
|
||||
int OOffset = (X * 4 + TX + (Y * 4 + TY) * W * 4) * 4;
|
||||
|
||||
Output[OOffset + 0] = Tile[TOffset + 0];
|
||||
Output[OOffset + 1] = Tile[TOffset + 1];
|
||||
Output[OOffset + 2] = Tile[TOffset + 2];
|
||||
Output[OOffset + 3] = Tile[TOffset + 3];
|
||||
|
||||
TOffset += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return BitmapExtension.GetBitmap(Output, W * 4, H * 4);
|
||||
}
|
||||
public static Bitmap DecompressBC3(Byte[] data, int width, int height, bool IsSRGB)
|
||||
{
|
||||
int W = (width + 3) / 4;
|
||||
int H = (height + 3) / 4;
|
||||
|
||||
byte[] Output = new byte[W * H * 64];
|
||||
|
||||
for (int Y = 0; Y < H; Y++)
|
||||
{
|
||||
for (int X = 0; X < W; X++)
|
||||
{
|
||||
int IOffs = (Y * W + X) * 16;
|
||||
|
||||
byte[] Tile = BCnDecodeTile(data, IOffs + 8, false);
|
||||
|
||||
byte[] Alpha = new byte[8];
|
||||
|
||||
Alpha[0] = data[IOffs + 0];
|
||||
Alpha[1] = data[IOffs + 1];
|
||||
|
||||
CalculateBC3Alpha(Alpha);
|
||||
|
||||
int AlphaLow = Get32(data, IOffs + 2);
|
||||
int AlphaHigh = Get16(data, IOffs + 6);
|
||||
|
||||
ulong AlphaCh = (uint)AlphaLow | (ulong)AlphaHigh << 32;
|
||||
|
||||
int TOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < 4; TY++)
|
||||
{
|
||||
for (int TX = 0; TX < 4; TX++)
|
||||
{
|
||||
int OOffset = (X * 4 + TX + (Y * 4 + TY) * W * 4) * 4;
|
||||
|
||||
byte AlphaPx = Alpha[(AlphaCh >> (TY * 12 + TX * 3)) & 7];
|
||||
|
||||
Output[OOffset + 0] = Tile[TOffset + 0];
|
||||
Output[OOffset + 1] = Tile[TOffset + 1];
|
||||
Output[OOffset + 2] = Tile[TOffset + 2];
|
||||
Output[OOffset + 3] = AlphaPx;
|
||||
|
||||
TOffset += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BitmapExtension.GetBitmap(Output, W * 4, H * 4);
|
||||
}
|
||||
|
||||
public static Bitmap DecompressBC4(Byte[] data, int width, int height, bool IsSNORM)
|
||||
{
|
||||
int W = (width + 3) / 4;
|
||||
int H = (height + 3) / 4;
|
||||
|
||||
byte[] Output = new byte[W * H * 64];
|
||||
|
||||
for (int Y = 0; Y < H; Y++)
|
||||
{
|
||||
for (int X = 0; X < W; X++)
|
||||
{
|
||||
int IOffs = (Y * W + X) * 8;
|
||||
|
||||
byte[] Red = new byte[8];
|
||||
|
||||
Red[0] = data[IOffs + 0];
|
||||
Red[1] = data[IOffs + 1];
|
||||
|
||||
CalculateBC3Alpha(Red);
|
||||
|
||||
int RedLow = Get32(data, IOffs + 2);
|
||||
int RedHigh = Get16(data, IOffs + 6);
|
||||
|
||||
ulong RedCh = (uint)RedLow | (ulong)RedHigh << 32;
|
||||
|
||||
int TOffset = 0;
|
||||
int TW = Math.Min(width - X * 4, 4);
|
||||
int TH = Math.Min(height - Y * 4, 4);
|
||||
|
||||
for (int TY = 0; TY < 4; TY++)
|
||||
{
|
||||
for (int TX = 0; TX < 4; TX++)
|
||||
{
|
||||
int OOffset = (X * 4 + TX + (Y * 4 + TY) * W * 4) * 4;
|
||||
|
||||
byte RedPx = Red[(RedCh >> (TY * 12 + TX * 3)) & 7];
|
||||
|
||||
Output[OOffset + 0] = RedPx;
|
||||
Output[OOffset + 1] = RedPx;
|
||||
Output[OOffset + 2] = RedPx;
|
||||
Output[OOffset + 3] = 255;
|
||||
|
||||
TOffset += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BitmapExtension.GetBitmap(Output, W * 4, H * 4);
|
||||
}
|
||||
public static byte[] DecompressBC5(Byte[] data, int width, int height, bool IsSNORM, bool IsByteArray)
|
||||
{
|
||||
int W = (width + 3) / 4;
|
||||
int H = (height + 3) / 4;
|
||||
|
||||
|
||||
byte[] Output = new byte[W * H * 64];
|
||||
|
||||
for (int Y = 0; Y < H; Y++)
|
||||
{
|
||||
for (int X = 0; X < W; X++)
|
||||
|
||||
{
|
||||
int IOffs = (Y * W + X) * 16;
|
||||
byte[] Red = new byte[8];
|
||||
byte[] Green = new byte[8];
|
||||
|
||||
Red[0] = data[IOffs + 0];
|
||||
Red[1] = data[IOffs + 1];
|
||||
|
||||
Green[0] = data[IOffs + 8];
|
||||
Green[1] = data[IOffs + 9];
|
||||
|
||||
if (IsSNORM == true)
|
||||
{
|
||||
CalculateBC3AlphaS(Red);
|
||||
CalculateBC3AlphaS(Green);
|
||||
}
|
||||
else
|
||||
{
|
||||
CalculateBC3Alpha(Red);
|
||||
CalculateBC3Alpha(Green);
|
||||
}
|
||||
|
||||
int RedLow = Get32(data, IOffs + 2);
|
||||
int RedHigh = Get16(data, IOffs + 6);
|
||||
|
||||
int GreenLow = Get32(data, IOffs + 10);
|
||||
int GreenHigh = Get16(data, IOffs + 14);
|
||||
|
||||
ulong RedCh = (uint)RedLow | (ulong)RedHigh << 32;
|
||||
ulong GreenCh = (uint)GreenLow | (ulong)GreenHigh << 32;
|
||||
|
||||
int TW = Math.Min(width - X * 4, 4);
|
||||
int TH = Math.Min(height - Y * 4, 4);
|
||||
|
||||
|
||||
if (IsSNORM == true)
|
||||
{
|
||||
for (int TY = 0; TY < TH; TY++)
|
||||
{
|
||||
for (int TX = 0; TX < TW; TX++)
|
||||
{
|
||||
|
||||
int Shift = TY * 12 + TX * 3;
|
||||
int OOffset = ((Y * 4 + TY) * width + (X * 4 + TX)) * 4;
|
||||
|
||||
byte RedPx = Red[(RedCh >> Shift) & 7];
|
||||
byte GreenPx = Green[(GreenCh >> Shift) & 7];
|
||||
|
||||
if (IsSNORM == true)
|
||||
{
|
||||
RedPx += 0x80;
|
||||
GreenPx += 0x80;
|
||||
}
|
||||
|
||||
float NX = (RedPx / 255f) * 2 - 1;
|
||||
float NY = (GreenPx / 255f) * 2 - 1;
|
||||
float NZ = (float)Math.Sqrt(1 - (NX * NX + NY * NY));
|
||||
|
||||
Output[OOffset + 0] = Clamp((NX + 1) * 0.5f);
|
||||
Output[OOffset + 1] = Clamp((NY + 1) * 0.5f);
|
||||
Output[OOffset + 2] = Clamp((NZ + 1) * 0.5f);
|
||||
Output[OOffset + 3] = 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int TY = 0; TY < TH; TY++)
|
||||
{
|
||||
for (int TX = 0; TX < TW; TX++)
|
||||
{
|
||||
|
||||
int Shift = TY * 12 + TX * 3;
|
||||
int OOffset = ((Y * 4 + TY) * width + (X * 4 + TX)) * 4;
|
||||
|
||||
byte RedPx = Red[(RedCh >> Shift) & 7];
|
||||
byte GreenPx = Green[(GreenCh >> Shift) & 7];
|
||||
|
||||
Output[OOffset + 0] = RedPx;
|
||||
Output[OOffset + 1] = GreenPx;
|
||||
Output[OOffset + 2] = 255;
|
||||
Output[OOffset + 3] = 255;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Output;
|
||||
}
|
||||
public static Bitmap DecompressBC5(Byte[] data, int width, int height, bool IsSNORM)
|
||||
{
|
||||
int W = (width + 3) / 4;
|
||||
int H = (height + 3) / 4;
|
||||
|
||||
|
||||
byte[] Output = new byte[W * H * 64];
|
||||
|
||||
for (int Y = 0; Y < H; Y++)
|
||||
{
|
||||
for (int X = 0; X < W; X++)
|
||||
|
||||
{
|
||||
int IOffs = (Y * W + X) * 16;
|
||||
byte[] Red = new byte[8];
|
||||
byte[] Green = new byte[8];
|
||||
|
||||
Red[0] = data[IOffs + 0];
|
||||
Red[1] = data[IOffs + 1];
|
||||
|
||||
Green[0] = data[IOffs + 8];
|
||||
Green[1] = data[IOffs + 9];
|
||||
|
||||
if (IsSNORM == true)
|
||||
{
|
||||
CalculateBC3AlphaS(Red);
|
||||
CalculateBC3AlphaS(Green);
|
||||
}
|
||||
else
|
||||
{
|
||||
CalculateBC3Alpha(Red);
|
||||
CalculateBC3Alpha(Green);
|
||||
}
|
||||
|
||||
int RedLow = Get32(data, IOffs + 2);
|
||||
int RedHigh = Get16(data, IOffs + 6);
|
||||
|
||||
int GreenLow = Get32(data, IOffs + 10);
|
||||
int GreenHigh = Get16(data, IOffs + 14);
|
||||
|
||||
ulong RedCh = (uint)RedLow | (ulong)RedHigh << 32;
|
||||
ulong GreenCh = (uint)GreenLow | (ulong)GreenHigh << 32;
|
||||
|
||||
int TW = Math.Min(width - X * 4, 4);
|
||||
int TH = Math.Min(height - Y * 4, 4);
|
||||
|
||||
|
||||
if (IsSNORM == true)
|
||||
{
|
||||
for (int TY = 0; TY < TH; TY++)
|
||||
{
|
||||
for (int TX = 0; TX < TW; TX++)
|
||||
{
|
||||
|
||||
int Shift = TY * 12 + TX * 3;
|
||||
int OOffset = ((Y * 4 + TY) * width + (X * 4 + TX)) * 4;
|
||||
|
||||
byte RedPx = Red[(RedCh >> Shift) & 7];
|
||||
byte GreenPx = Green[(GreenCh >> Shift) & 7];
|
||||
|
||||
if (IsSNORM == true)
|
||||
{
|
||||
RedPx += 0x80;
|
||||
GreenPx += 0x80;
|
||||
}
|
||||
|
||||
float NX = (RedPx / 255f) * 2 - 1;
|
||||
float NY = (GreenPx / 255f) * 2 - 1;
|
||||
float NZ = (float)Math.Sqrt(1 - (NX * NX + NY * NY));
|
||||
|
||||
Output[OOffset + 0] = Clamp((NZ + 1) * 0.5f);
|
||||
Output[OOffset + 1] = Clamp((NY + 1) * 0.5f);
|
||||
Output[OOffset + 2] = Clamp((NX + 1) * 0.5f);
|
||||
Output[OOffset + 3] = 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int TY = 0; TY < TH; TY++)
|
||||
{
|
||||
for (int TX = 0; TX < TW; TX++)
|
||||
{
|
||||
|
||||
int Shift = TY * 12 + TX * 3;
|
||||
int OOffset = ((Y * 4 + TY) * width + (X * 4 + TX)) * 4;
|
||||
|
||||
byte RedPx = Red[(RedCh >> Shift) & 7];
|
||||
byte GreenPx = Green[(GreenCh >> Shift) & 7];
|
||||
|
||||
Output[OOffset + 0] = 255;
|
||||
Output[OOffset + 1] = GreenPx;
|
||||
Output[OOffset + 2] = RedPx;
|
||||
Output[OOffset + 3] = 255;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return BitmapExtension.GetBitmap(Output, W * 4, H * 4);
|
||||
}
|
||||
|
||||
public static Bitmap DecompressBC6(Byte[] data, int width, int height, bool IsSNORM)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public static Bitmap DecompressBC7(Byte[] data, int width, int height, bool IsSNORM)
|
||||
{
|
||||
byte[] decomp = new byte[0];
|
||||
|
||||
if (IsSNORM)
|
||||
decomp = DirectXTex.ImageCompressor.Decompress(data, width, height, (int)DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM_SRGB);
|
||||
else
|
||||
decomp = DirectXTex.ImageCompressor.Decompress(data, width, height, (int)DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM);
|
||||
|
||||
return BitmapExtension.GetBitmap(decomp, width, height);
|
||||
}
|
||||
|
||||
public static int Get16(byte[] Data, int Address)
|
||||
{
|
||||
return
|
||||
Data[Address + 0] << 0 |
|
||||
Data[Address + 1] << 8;
|
||||
}
|
||||
|
||||
public static int Get32(byte[] Data, int Address)
|
||||
{
|
||||
return
|
||||
Data[Address + 0] << 0 |
|
||||
Data[Address + 1] << 8 |
|
||||
Data[Address + 2] << 16 |
|
||||
Data[Address + 3] << 24;
|
||||
}
|
||||
|
||||
private static byte Clamp(float Value)
|
||||
{
|
||||
if (Value > 1)
|
||||
{
|
||||
return 0xff;
|
||||
}
|
||||
else if (Value < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (byte)(Value * 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CalculateBC3Alpha(byte[] Alpha)
|
||||
{
|
||||
for (int i = 2; i < 8; i++)
|
||||
{
|
||||
if (Alpha[0] > Alpha[1])
|
||||
{
|
||||
Alpha[i] = (byte)(((8 - i) * Alpha[0] + (i - 1) * Alpha[1]) / 7);
|
||||
}
|
||||
else if (i < 6)
|
||||
{
|
||||
Alpha[i] = (byte)(((6 - i) * Alpha[0] + (i - 1) * Alpha[1]) / 7);
|
||||
}
|
||||
else if (i == 6)
|
||||
{
|
||||
Alpha[i] = 0;
|
||||
}
|
||||
else /* i == 7 */
|
||||
{
|
||||
Alpha[i] = 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void CalculateBC3AlphaS(byte[] Alpha)
|
||||
{
|
||||
for (int i = 2; i < 8; i++)
|
||||
{
|
||||
if ((sbyte)Alpha[0] > (sbyte)Alpha[1])
|
||||
{
|
||||
Alpha[i] = (byte)(((8 - i) * (sbyte)Alpha[0] + (i - 1) * (sbyte)Alpha[1]) / 7);
|
||||
}
|
||||
else if (i < 6)
|
||||
{
|
||||
Alpha[i] = (byte)(((6 - i) * (sbyte)Alpha[0] + (i - 1) * (sbyte)Alpha[1]) / 7);
|
||||
}
|
||||
else if (i == 6)
|
||||
{
|
||||
Alpha[i] = 0x80;
|
||||
}
|
||||
else /* i == 7 */
|
||||
{
|
||||
Alpha[i] = 0x7f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] DecodeBC7(int X, int Y, int block)
|
||||
{
|
||||
byte[] result = null;
|
||||
|
||||
//Alright so BC7 decompression as multple modes
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public class DDS_PixelDecode
|
||||
{
|
||||
public static Bitmap DecodeR8G8(Byte[] data, int width, int height)
|
||||
{
|
||||
byte[] Output = new byte[width * height * 4];
|
||||
|
||||
int OOffset = 0;
|
||||
|
||||
int W = (width + 3) / 4;
|
||||
int H = (height + 3) / 4;
|
||||
|
||||
for (int Y = 0; Y < H; Y++)
|
||||
{
|
||||
for (int X = 0; X < W; X++)
|
||||
{
|
||||
int IOffs = (Y * W + X) * 2;
|
||||
|
||||
Output[OOffset + 1] = data[IOffs + 1];
|
||||
Output[OOffset + 2] = data[IOffs + 0];
|
||||
Output[OOffset + 3] = 0xff;
|
||||
|
||||
OOffset += 4;
|
||||
}
|
||||
}
|
||||
|
||||
return BitmapExtension.GetBitmap(Output, width, height);
|
||||
}
|
||||
public static Bitmap DecodeR8G8B8A8(Byte[] data, int width, int height)
|
||||
{
|
||||
byte[] Output = new byte[width * height * 4];
|
||||
|
||||
int OOffset = 0;
|
||||
|
||||
for (int Y = 0; Y < height; Y++)
|
||||
{
|
||||
for (int X = 0; X < width; X++)
|
||||
{
|
||||
int IOffs = OOffset;
|
||||
|
||||
Output[OOffset + 0] = data[IOffs + 2];
|
||||
Output[OOffset + 1] = data[IOffs + 1];
|
||||
Output[OOffset + 2] = data[IOffs + 0];
|
||||
Output[OOffset + 3] = data[IOffs + 3];
|
||||
|
||||
OOffset += 4;
|
||||
}
|
||||
}
|
||||
|
||||
return BitmapExtension.GetBitmap(Output, width, height);
|
||||
}
|
||||
public static byte[] EncodeR8G8B8A8(Byte[] data, int width, int height, int Offset)
|
||||
{
|
||||
byte[] Output = new byte[width * height * 4];
|
||||
|
||||
int OOffset = 0;
|
||||
|
||||
for (int Y = 0; Y < height; Y++)
|
||||
{
|
||||
for (int X = 0; X < width; X++)
|
||||
{
|
||||
int IOffs = (X * 4 + X + (Y * 4 + Y) * width * 4) * 4;
|
||||
|
||||
Output[OOffset + 0] = data[IOffs + 2];
|
||||
Output[OOffset + 1] = data[IOffs + 1];
|
||||
Output[OOffset + 2] = data[IOffs + 0];
|
||||
Output[OOffset + 3] = data[IOffs + 3];
|
||||
|
||||
OOffset += 4;
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -108,7 +108,6 @@
|
|||
<Compile Include="FileFormats\ANIM.cs" />
|
||||
<Compile Include="FileFormats\Assimp\Assimp.cs" />
|
||||
<Compile Include="FileFormats\Assimp\AssimpHelper.cs" />
|
||||
<Compile Include="FileFormats\DDS_PixelDecode.cs" />
|
||||
<Compile Include="FileFormats\CSV.cs" />
|
||||
<Compile Include="FileFormats\DDS.cs" />
|
||||
<Compile Include="FileFormats\DDSCompressor.cs" />
|
||||
|
|
Loading…
Reference in a new issue