Support R4G4 decoding
This commit is contained in:
parent
017c1ab1e3
commit
489d47243b
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -581,7 +581,7 @@ namespace Bfres.Structs
|
||||
case GX2SurfaceFormat.TC_R11_G11_B10_Float: return TEX_FORMAT.R11G11B10_FLOAT;
|
||||
case GX2SurfaceFormat.TCD_R16_UNorm: return TEX_FORMAT.R16_UNORM;
|
||||
case GX2SurfaceFormat.TCD_R32_Float: return TEX_FORMAT.R32_FLOAT;
|
||||
case GX2SurfaceFormat.T_R4_G4_UNorm: return TEX_FORMAT.B4G4R4A4_UNORM;
|
||||
case GX2SurfaceFormat.T_R4_G4_UNorm: return TEX_FORMAT.R4G4_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;
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public class A8
|
||||
{
|
||||
public static byte[] Decompress(byte[] Input, int Width, int Height, bool Alpha)
|
||||
{
|
||||
byte[] Output = new byte[Width * Height * 4];
|
||||
|
||||
int bpp = 16;
|
||||
int Increment = bpp / 8;
|
||||
|
||||
int IOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < Height; TY += 8)
|
||||
{
|
||||
for (int TX = 0; TX < Width; TX += 8)
|
||||
{
|
||||
for (int Px = 0; Px < 64; Px++)
|
||||
{
|
||||
int X = Swizzle_3DS.SwizzleLUT[Px] & 7;
|
||||
int Y = (Swizzle_3DS.SwizzleLUT[Px] - X) >> 3;
|
||||
|
||||
int OOffet = (TX + X + ((Height - 1 - (TY + Y)) * Width)) * 4;
|
||||
|
||||
Output[OOffet + 0] = 0xff;
|
||||
Output[OOffet + 1] = 0xff;
|
||||
Output[OOffet + 2] = 0xff;
|
||||
Output[OOffet + 3] = Input[IOffset];
|
||||
|
||||
IOffset += Increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
}
|
||||
}
|
@ -207,4 +207,4 @@ namespace Switch_Toolbox.Library
|
||||
return (byte)Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public class HiLo8
|
||||
{
|
||||
public static byte[] Decompress(byte[] Input, int Width, int Height, bool Alpha)
|
||||
{
|
||||
byte[] Output = new byte[Width * Height * 4];
|
||||
|
||||
int bpp = 16;
|
||||
int Increment = 16 / 8;
|
||||
|
||||
int IOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < Height; TY += 8)
|
||||
{
|
||||
for (int TX = 0; TX < Width; TX += 8)
|
||||
{
|
||||
for (int Px = 0; Px < 64; Px++)
|
||||
{
|
||||
int X = Swizzle_3DS.SwizzleLUT[Px] & 7;
|
||||
int Y = (Swizzle_3DS.SwizzleLUT[Px] - X) >> 3;
|
||||
|
||||
int OOffet = (TX + X + ((Height - 1 - (TY + Y)) * Width)) * 4;
|
||||
|
||||
Output[OOffet + 0] = Input[IOffset + 1];
|
||||
Output[OOffet + 1] = Input[IOffset + 0];
|
||||
Output[OOffet + 2] = 0;
|
||||
Output[OOffet + 3] = 0xff;
|
||||
|
||||
IOffset += Increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public class L4
|
||||
{
|
||||
public static byte[] Decompress(byte[] Input, int Width, int Height, bool Alpha)
|
||||
{
|
||||
byte[] Output = new byte[Width * Height * 4];
|
||||
|
||||
int bpp = 16;
|
||||
int Increment = 16 / 8;
|
||||
|
||||
int IOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < Height; TY += 8)
|
||||
{
|
||||
for (int TX = 0; TX < Width; TX += 8)
|
||||
{
|
||||
for (int Px = 0; Px < 64; Px++)
|
||||
{
|
||||
int X = Swizzle_3DS.SwizzleLUT[Px] & 7;
|
||||
int Y = (Swizzle_3DS.SwizzleLUT[Px] - X) >> 3;
|
||||
|
||||
int OOffet = (TX + X + ((Height - 1 - (TY + Y)) * Width)) * 4;
|
||||
|
||||
int L = (Input[IOffset >> 1] >> ((IOffset & 1) << 2)) & 0xf;
|
||||
Output[OOffet + 0] = (byte)((L << 4) | L);
|
||||
Output[OOffet + 1] = (byte)((L << 4) | L);
|
||||
Output[OOffet + 2] = (byte)((L << 4) | L);
|
||||
Output[OOffet + 3] = 0xff;
|
||||
|
||||
IOffset += Increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public class L8
|
||||
{
|
||||
public static byte[] Decompress(byte[] Input, int Width, int Height, bool Alpha)
|
||||
{
|
||||
byte[] Output = new byte[Width * Height * 4];
|
||||
|
||||
int bpp = 16;
|
||||
int Increment = 16 / 8;
|
||||
|
||||
int IOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < Height; TY += 8)
|
||||
{
|
||||
for (int TX = 0; TX < Width; TX += 8)
|
||||
{
|
||||
for (int Px = 0; Px < 64; Px++)
|
||||
{
|
||||
int X = Swizzle_3DS.SwizzleLUT[Px] & 7;
|
||||
int Y = (Swizzle_3DS.SwizzleLUT[Px] - X) >> 3;
|
||||
|
||||
int OOffet = (TX + X + ((Height - 1 - (TY + Y)) * Width)) * 4;
|
||||
|
||||
Output[OOffet + 0] = Input[IOffset];
|
||||
Output[OOffet + 1] = Input[IOffset];
|
||||
Output[OOffet + 2] = Input[IOffset];
|
||||
Output[OOffet + 3] = 0xff;
|
||||
|
||||
IOffset += Increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public class L4A
|
||||
{
|
||||
public static byte[] Decompress(byte[] Input, int Width, int Height, bool Alpha)
|
||||
{
|
||||
byte[] Output = new byte[Width * Height * 4];
|
||||
|
||||
int bpp = 16;
|
||||
int Increment = 16 / 8;
|
||||
|
||||
int IOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < Height; TY += 8)
|
||||
{
|
||||
for (int TX = 0; TX < Width; TX += 8)
|
||||
{
|
||||
for (int Px = 0; Px < 64; Px++)
|
||||
{
|
||||
int X = Swizzle_3DS.SwizzleLUT[Px] & 7;
|
||||
int Y = (Swizzle_3DS.SwizzleLUT[Px] - X) >> 3;
|
||||
|
||||
int OOffet = (TX + X + ((Height - 1 - (TY + Y)) * Width)) * 4;
|
||||
|
||||
Output[OOffet + 0] = (byte)((Input[IOffset] >> 4) | (Input[IOffset] & 0xf0));
|
||||
Output[OOffet + 1] = (byte)((Input[IOffset] >> 4) | (Input[IOffset] & 0xf0));
|
||||
Output[OOffet + 2] = (byte)((Input[IOffset] >> 4) | (Input[IOffset] & 0xf0));
|
||||
Output[OOffet + 3] = (byte)((Input[IOffset] << 4) | (Input[IOffset] & 0x0f));
|
||||
|
||||
IOffset += Increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public class L8A
|
||||
{
|
||||
public static byte[] Decompress(byte[] Input, int Width, int Height, bool Alpha)
|
||||
{
|
||||
byte[] Output = new byte[Width * Height * 4];
|
||||
|
||||
int bpp = 16;
|
||||
int Increment = 16 / 8;
|
||||
|
||||
int IOffset = 0;
|
||||
|
||||
for (int TY = 0; TY < Height; TY += 8)
|
||||
{
|
||||
for (int TX = 0; TX < Width; TX += 8)
|
||||
{
|
||||
for (int Px = 0; Px < 64; Px++)
|
||||
{
|
||||
int X = Swizzle_3DS.SwizzleLUT[Px] & 7;
|
||||
int Y = (Swizzle_3DS.SwizzleLUT[Px] - X) >> 3;
|
||||
|
||||
int OOffet = (TX + X + ((Height - 1 - (TY + Y)) * Width)) * 4;
|
||||
|
||||
Output[OOffet + 0] = Input[IOffset + 1];
|
||||
Output[OOffet + 1] = Input[IOffset + 1];
|
||||
Output[OOffet + 2] = Input[IOffset + 1];
|
||||
Output[OOffet + 3] = Input[IOffset + 0];
|
||||
|
||||
IOffset += Increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
}
|
||||
}
|
43
Switch_Toolbox_Library/FileFormats/R4G4.cs
Normal file
43
Switch_Toolbox_Library/FileFormats/R4G4.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public class R4G4
|
||||
{
|
||||
public static byte[] Decompress(byte[] Input, int Width, int Height, bool Alpha)
|
||||
{
|
||||
byte[] Output = new byte[Width * Height * 4];
|
||||
|
||||
byte[] comp = new byte[4] { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
|
||||
int bpp = (int)STGenericTexture.GetBytesPerPixel(TEX_FORMAT.R4G4_UNORM);
|
||||
|
||||
for (int Y = 0; Y < Height; Y++)
|
||||
{
|
||||
for (int X = 0; X < Width; X++)
|
||||
{
|
||||
int InputOffset = (Y * Width + X) * bpp;
|
||||
int OutputOffset = (Y * Width + X) * 4;
|
||||
|
||||
int pixel = 0;
|
||||
for (int i = 0; i < bpp; i++)
|
||||
pixel |= Input[InputOffset + i] << (8 * i);
|
||||
|
||||
comp[0] = (byte)((pixel & 0xF) * 17);
|
||||
comp[1] = (byte)(((pixel & 0xF0) >> 4) * 17);
|
||||
|
||||
Output[OutputOffset + 0] = comp[0];
|
||||
Output[OutputOffset + 1] = comp[1];
|
||||
Output[OutputOffset + 2] = comp[2];
|
||||
Output[OutputOffset + 3] = comp[3];
|
||||
}
|
||||
}
|
||||
|
||||
return Output;
|
||||
}
|
||||
}
|
||||
}
|
@ -210,6 +210,7 @@ namespace Switch_Toolbox.Library
|
||||
{ TEX_FORMAT.A8_UNORM, new FormatInfo(1, 1, 1, 1, TargetBuffer.Color) },
|
||||
{ TEX_FORMAT.R8_SINT, new FormatInfo(1, 1, 1, 1, TargetBuffer.Color) },
|
||||
{ TEX_FORMAT.R8_SNORM, new FormatInfo(1, 1, 1, 1, TargetBuffer.Color) },
|
||||
{ TEX_FORMAT.R4G4_UNORM, new FormatInfo(1, 1, 1, 1, TargetBuffer.Color) },
|
||||
{ TEX_FORMAT.R8_UINT, new FormatInfo(1, 1, 1, 1, TargetBuffer.Color) },
|
||||
{ TEX_FORMAT.R8_UNORM, new FormatInfo(1, 1, 1, 1, TargetBuffer.Color) },
|
||||
{ TEX_FORMAT.R11G11B10_FLOAT, new FormatInfo(4, 1, 1, 1, TargetBuffer.Color) },
|
||||
@ -344,6 +345,9 @@ namespace Switch_Toolbox.Library
|
||||
|
||||
switch (Format)
|
||||
{
|
||||
case TEX_FORMAT.R4G4_UNORM:
|
||||
return BitmapExtension.GetBitmap(R4G4.Decompress(data, (int)width, (int)height, false),
|
||||
(int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
case TEX_FORMAT.BC5_SNORM:
|
||||
return DDSCompressor.DecompressBC5(data, (int)width, (int)height, true);
|
||||
case TEX_FORMAT.ETC1:
|
||||
|
@ -167,5 +167,6 @@ namespace Switch_Toolbox.Library
|
||||
LA8 = 235,
|
||||
HIL08 = 236,
|
||||
A4 = 237,
|
||||
R4G4_UNORM = 238,
|
||||
}
|
||||
}
|
||||
|
@ -200,11 +200,7 @@
|
||||
<Compile Include="Audio\AudioFileRipper.cs" />
|
||||
<Compile Include="Audio\VGAudioFile.cs" />
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="FileFormats\3DS\HiLo8.cs" />
|
||||
<Compile Include="FileFormats\3DS\A8.cs" />
|
||||
<Compile Include="FileFormats\3DS\L4.cs" />
|
||||
<Compile Include="FileFormats\3DS\LA4.cs" />
|
||||
<Compile Include="FileFormats\3DS\LA8.cs" />
|
||||
<Compile Include="FileFormats\3DS\ETC1.cs" />
|
||||
<Compile Include="FileFormats\Animation\SMD.cs" />
|
||||
<Compile Include="FileFormats\APNG\APNG.cs" />
|
||||
<Compile Include="FileFormats\APNG\CRC.cs" />
|
||||
@ -213,9 +209,8 @@
|
||||
<Compile Include="FileFormats\DAE\ColladaHelper.cs" />
|
||||
<Compile Include="FileFormats\DAE\collada_schema_1_4.cs" />
|
||||
<Compile Include="FileFormats\DAE\DAE.cs" />
|
||||
<Compile Include="FileFormats\3DS\ETC1.cs" />
|
||||
<Compile Include="FileFormats\3DS\L8.cs" />
|
||||
<Compile Include="FileFormats\OBJ.cs" />
|
||||
<Compile Include="FileFormats\R4G4.cs" />
|
||||
<Compile Include="Forms\BatchFormatExport.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
Loading…
x
Reference in New Issue
Block a user