-
Notifications
You must be signed in to change notification settings - Fork 9
/
TX.bt
159 lines (143 loc) · 3.75 KB
/
TX.bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//------------------------------------------------
//--- 010 Editor v8.0.1 Binary Template
//
// File:
// Authors:
// Version:
// Purpose:
// Category:
// File Mask:
// ID Bytes:
// History:
//------------------------------------------------
struct {
local float height, width;
local int DXT = 0;
local int i;
} locals <hidden=true>;
typedef enum <char> {
DXT1,
DXT3,
DXT5
} DXT_TYPE <name="DXT version">;
typedef enum <uint> {
D3DFMT_A8R8G8B8 = 21,
D3DFMT_X8R8G8B8 = 22,
D3DFMT_R5G6B5 = 23,
D3DFMT_X1R5G5B5 = 24,
D3DFMT_A1R5G5B5 = 25,
D3DFMT_A4R4G4B4 = 26
} D3DFORMAT;
struct {
UINT Version;
UINT Width;
UINT Height;
UINT MapsCount;
union {
DXT_TYPE DXT[4];
D3DFORMAT D3DFormat;
} IMAGE_TYPE;
UINT Size <name="Image size">;
} HEADER <name="File header">;
BitfieldDisablePadding();
typedef struct {
switch (HEADER.IMAGE_TYPE.D3DFormat)
{
case 21: // A8R8G8B8
ubyte Red <name="Red">;
ubyte Green <name="Green">;
ubyte Blue <name="Blue">;
ubyte Alpha <name="Alpha">;
break;
case 22: // X8R8G8B8
ubyte Red <name="Red">;
ubyte Green <name="Green">;
ubyte Blue <name="Blue">;
ubyte X <name="X">;
break;
case 23: // R5G6B5
ubyte Red : 5 <name="Red">;
ubyte Green : 6 <name="Green">;
ubyte Blue : 5 <name="Blue">;
break;
case 26:
ubyte Red : 4 <name="Red">;
ubyte Green : 4 <name="Green">;
ubyte Blue : 4 <name="Blue">;
ubyte Alpha : 4 <name="Alpha">;
}
} PIXEL <name="Pixel", size=sizePixel>;
typedef struct {
if (HEADER.IMAGE_TYPE.DXT != "DXT1")
{
struct {
if (HEADER.IMAGE_TYPE.DXT != "DXT5") {
for (locals.i = 0; locals.i < 16; ++locals.i) {
ubyte AlphaIndex : 4 <name="Alpha Index">;
}
}
else {
ubyte Alpha1;
ubyte Alpha2;
for (locals.i = 0; locals.i < 16; ++locals.i) {
ubyte AlphaIndex : 3 <name="Alpha Index">;
}
}
} AlphaChannel <name="Alpha Channel Data">;
};
struct {
struct {
ubyte Red : 5 <name="Red">;
ubyte Green : 6 <name="Green">;
ubyte Blue : 5 <name="Blue">;
} Color1;
struct {
ubyte Red : 5 <name="Red">;
ubyte Green : 6 <name="Green">;
ubyte Blue : 5 <name="Blue">;
} Color2;
struct {
for (locals.i = 0; locals.i < 16; ++locals.i)
ubyte PixelIndex : 2 <name="Pixel Index">;
} INDEX_TABLE;
} COLOR_DATA <name="Color Data">;
} TEXEL <name="Pixel", size=sizeTEXEL>;
int sizeTEXEL( TEXEL &texel )
{
if (HEADER.IMAGE_TYPE.DXT != "DXT1")
return 16;
else
return 8;
};
int sizePixel( PIXEL &pixel )
{
if (HEADER.IMAGE_TYPE.D3DFormat == 21 || HEADER.IMAGE_TYPE.D3DFormat == 22)
return 4;
else
return 2;
};
typedef struct (int arraySize) {
PIXEL array[arraySize] <optimize=false>;
} PIXEL_ARRAY;
typedef struct (int arraySize) {
TEXEL array[arraySize] <optimize=false>;
} TEXEL_ARRAY;
if (HEADER.IMAGE_TYPE.D3DFormat <= 26)
PIXEL_ARRAY Pixels(HEADER.Width*HEADER.Height) <name="Pixel Array">;
else
TEXEL_ARRAY Pixels(HEADER.Width*HEADER.Height/16) <name="Pixel Array (DXT compression)">;
typedef struct {
locals.height = HEADER.Height, locals.width = HEADER.Width;
while (1)
{
locals.height = locals.height/2.0;
locals.width = locals.width/2.0;
if (HEADER.IMAGE_TYPE.D3DFormat == 21)
PIXEL_ARRAY MipMaps(locals.height*locals.width) <name="MipMap">;
else
TEXEL_ARRAY MipMaps(locals.height*locals.width) <name="MipMap">;
if (locals.height == 1) break;
};
} MIP_MAPS <name="MipMaps">;
if (HEADER.MapsCount > 1)
MIP_MAPS MipMaps;