@@ -45,16 +45,47 @@ public static byte[] ToRGBA(this HMXBitmap bitmap, SystemInfo info)
45
45
case TPL_CMP_2 :
46
46
case TPL_CMP_ALPHA :
47
47
// Wii textures
48
- var tempData = new byte [ ( ( bitmap . Width * bitmap . Height ) * bitmap . Bpp ) / 8 ] ; // Just ignore mips
49
- Array . Copy ( bitmap . RawData , tempData , tempData . Length ) ;
48
+ if ( bitmap . Bpp == 4 && bitmap . WiiAlphaNumber == 4 )
49
+ {
50
+ // Hidden alpha texture after mips... ugh
51
+ var dxSize = ( bitmap . Width * bitmap . Height * bitmap . Bpp ) / 8 ;
52
+
53
+ var rgbData = new byte [ dxSize ] ;
54
+ var alphaData = new byte [ dxSize ] ;
55
+
56
+ Array . Copy ( bitmap . RawData , 0 , rgbData , 0 , rgbData . Length ) ;
57
+ Array . Copy ( bitmap . RawData , bitmap . RawData . Length - rgbData . Length , alphaData , 0 , alphaData . Length ) ;
58
+
59
+ // Remap blocks to DXT1
60
+ Texture . TPL . TPLToDXT1 ( bitmap . Width , bitmap . Height , rgbData ) ;
61
+ Texture . TPL . TPLToDXT1 ( bitmap . Width , bitmap . Height , alphaData ) ;
62
+
63
+ // Decode both images
64
+ var decodedImage = DecodeDxImage ( rgbData , bitmap . Width , bitmap . Height , 0 , DxEncoding . DXGI_FORMAT_BC1_UNORM ) ;
65
+ var decodedAlpha = DecodeDxImage ( alphaData , bitmap . Width , bitmap . Height , 0 , DxEncoding . DXGI_FORMAT_BC1_UNORM ) ;
50
66
51
- if ( bitmap . Bpp == 4 )
67
+ // Combine alpha channel
68
+ for ( int i = 0 ; i < decodedImage . Length ; i += 4 )
69
+ {
70
+ // Load from green channel
71
+ decodedImage [ i + 3 ] = decodedAlpha [ i + 1 ] ;
72
+ }
73
+
74
+ return decodedImage ;
75
+ }
76
+ else if ( bitmap . Bpp == 4 )
52
77
{
78
+ var tempData = new byte [ ( ( bitmap . Width * bitmap . Height ) * bitmap . Bpp ) / 8 ] ; // Just ignore mips
79
+ Array . Copy ( bitmap . RawData , tempData , tempData . Length ) ;
80
+
53
81
Texture . TPL . TPLToDXT1 ( bitmap . Width , bitmap . Height , tempData ) ;
54
82
return DecodeDxImage ( tempData , bitmap . Width , bitmap . Height , 0 , DxEncoding . DXGI_FORMAT_BC1_UNORM ) ;
55
83
}
56
84
else
57
85
{
86
+ var tempData = new byte [ ( ( bitmap . Width * bitmap . Height ) * bitmap . Bpp ) / 8 ] ; // Just ignore mips
87
+ Array . Copy ( bitmap . RawData , tempData , tempData . Length ) ;
88
+
58
89
// 8bpp wii texture is actually two DXT1 textures
59
90
var rgbData = tempData . AsSpan ( 0 , tempData . Length / 2 ) ;
60
91
var alphaData = tempData . AsSpan ( tempData . Length / 2 , tempData . Length / 2 ) ;
@@ -70,6 +101,7 @@ public static byte[] ToRGBA(this HMXBitmap bitmap, SystemInfo info)
70
101
// Combine alpha channel
71
102
for ( int i = 0 ; i < decodedImage . Length ; i += 4 )
72
103
{
104
+ // Load from green channel
73
105
decodedImage [ i + 3 ] = decodedAlpha [ i + 1 ] ;
74
106
}
75
107
0 commit comments