forked from GDRETools/gdsdecomp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_enum_compat.cpp
335 lines (317 loc) · 7.29 KB
/
image_enum_compat.cpp
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#include "image_enum_compat.h"
#include "core/error/error_macros.h"
const char *v2_format_names[V2Image::IMAGE_FORMAT_V2_MAX] = {
"Grayscale",
"Intensity",
"GrayscaleAlpha",
"RGB",
"RGBA",
"Indexed",
"IndexedAlpha",
"YUV422",
"YUV444",
"BC1",
"BC2",
"BC3",
"BC4",
"BC5",
"PVRTC2",
"PVRTC2Alpha",
"PVRTC4",
"PVRTC4Alpha",
"ETC",
"ATC",
"ATCAlphaExp",
"ATCAlphaInterp",
};
const char *v2_format_identifiers[V2Image::IMAGE_FORMAT_V2_MAX] = {
"GRAYSCALE",
"INTENSITY",
"GRAYSCALE_ALPHA",
"RGB",
"RGBA",
"INDEXED",
"INDEXED_ALPHA",
"YUV422",
"YUV444",
"BC1",
"BC2",
"BC3",
"BC4",
"BC5",
"PVRTC2",
"PVRTC2_ALPHA",
"PVRTC4",
"PVRTC4_ALPHA",
"ETC",
"ATC",
"ATC_ALPHA_EXPLICIT",
"ATC_ALPHA_INTERPOLATED"
};
const char *v3_format_identifiers[V3Image::FORMAT_MAX] = {
"L8", //luminance
"LA8", //luminance-alpha
"R8",
"RG8",
"RGB8",
"RGBA8",
"RGBA4444",
"RGBA5551",
"RF", //float
"RGF",
"RGBF",
"RGBAF",
"RH", //half float
"RGH",
"RGBH",
"RGBAH",
"RGBE9995",
"DXT1", //s3tc bc1
"DXT3", //bc2
"DXT5", //bc3
"RGTC_R",
"RGTC_RG",
"BPTC_RGBA", //btpc bc7
"BPTC_RGBF", //float bc6h
"BPTC_RGBFU", //unsigned float bc6hu
"PVRTC2", //pvrtc
"PVRTC2A",
"PVRTC4",
"PVRTC4A",
"ETC", //etc1
"ETC2_R11", //etc2
"ETC2_R11S", //signed, NOT srgb.
"ETC2_RG11",
"ETC2_RG11S",
"ETC2_RGB8",
"ETC2_RGBA8",
"ETC2_RGB8A1"
};
const char *v3_format_names[V3Image::FORMAT_MAX] = {
"Lum8", //luminance
"LumAlpha8", //luminance-alpha
"Red8",
"RedGreen",
"RGB8",
"RGBA8",
"RGBA4444",
"RGBA5551",
"RFloat", //float
"RGFloat",
"RGBFloat",
"RGBAFloat",
"RHalf", //half float
"RGHalf",
"RGBHalf",
"RGBAHalf",
"RGBE9995",
"DXT1 RGB8", //s3tc
"DXT3 RGBA8",
"DXT5 RGBA8",
"RGTC Red8",
"RGTC RedGreen8",
"BPTC_RGBA",
"BPTC_RGBF",
"BPTC_RGBFU",
"PVRTC2", //pvrtc
"PVRTC2A",
"PVRTC4",
"PVRTC4A",
"ETC", //etc1
"ETC2_R11", //etc2
"ETC2_R11S", //signed", NOT srgb.
"ETC2_RG11",
"ETC2_RG11S",
"ETC2_RGB8",
"ETC2_RGBA8",
"ETC2_RGB8A1",
};
const char *v4_format_identifiers[Image::FORMAT_MAX] = {
"L8", //luminance
"LA8", //luminance-alpha
"R8",
"RG8",
"RGB8",
"RGBA8",
"RGBA4444",
"RGB565",
"RF", //float
"RGF",
"RGBF",
"RGBAF",
"RH", //half float
"RGH",
"RGBH",
"RGBAH",
"RGBE9995",
"DXT1", //s3tc bc1
"DXT3", //bc2
"DXT5", //bc3
"RGTC_R",
"RGTC_RG",
"BPTC_RGBA", //btpc bc7
"BPTC_RGBF", //float bc6h
"BPTC_RGBFU", //unsigned float bc6hu
"ETC", //etc1
"ETC2_R11", //etc2
"ETC2_R11S", //signed, NOT srgb.
"ETC2_RG11",
"ETC2_RG11S",
"ETC2_RGB8",
"ETC2_RGBA8",
"ETC2_RGB8A1",
"ETC2_RA_AS_RG", //used to make basis universal happy
"DXT5_RA_AS_RG" //used to make basis universal happy
};
V2Image::Format ImageEnumCompat::get_v2_format_from_string(const String &fmt_id) {
if (fmt_id == "CUSTOM") {
return V2Image::IMAGE_FORMAT_CUSTOM;
}
for (int i = 0; i < V2Image::IMAGE_FORMAT_V2_MAX; i++) {
if (v2_format_names[i] == fmt_id) {
return (V2Image::Format)i;
}
}
return V2Image::IMAGE_FORMAT_V2_MAX;
}
String ImageEnumCompat::get_v2_format_name(V2Image::Format p_format) {
if (p_format == V2Image::IMAGE_FORMAT_CUSTOM) {
return "Custom";
}
ERR_FAIL_INDEX_V(p_format, V2Image::IMAGE_FORMAT_V2_MAX, String());
return v2_format_names[p_format];
}
String ImageEnumCompat::get_v2_format_identifier(V2Image::Format p_format) {
if (p_format == V2Image::IMAGE_FORMAT_CUSTOM) {
return "CUSTOM";
}
ERR_FAIL_INDEX_V(p_format, V2Image::IMAGE_FORMAT_V2_MAX, String());
return v2_format_identifiers[p_format];
}
String ImageEnumCompat::get_v3_format_name(V3Image::Format p_format) {
ERR_FAIL_INDEX_V(p_format, V3Image::FORMAT_MAX, String());
return v3_format_names[p_format];
}
String ImageEnumCompat::get_v3_format_identifier(V3Image::Format p_format) {
ERR_FAIL_INDEX_V(p_format, V3Image::FORMAT_MAX, String());
return v3_format_identifiers[p_format];
}
String ImageEnumCompat::get_v4_format_identifier(Image::Format p_format) {
ERR_FAIL_INDEX_V(p_format, Image::FORMAT_MAX, String());
return v4_format_identifiers[p_format];
}
String ImageEnumCompat::get_v2_format_identifier_pcfg(V2Image::Format p_format, int p_img_size) {
switch (p_format) {
case V2Image::IMAGE_FORMAT_GRAYSCALE:
return "grayscale";
break;
case V2Image::IMAGE_FORMAT_INTENSITY:
return "intensity";
break;
case V2Image::IMAGE_FORMAT_GRAYSCALE_ALPHA:
return "grayscale_alpha";
break;
case V2Image::IMAGE_FORMAT_RGB:
return "rgb";
break;
case V2Image::IMAGE_FORMAT_RGBA:
return "rgba";
break;
case V2Image::IMAGE_FORMAT_INDEXED:
return "indexed";
break;
case V2Image::IMAGE_FORMAT_INDEXED_ALPHA:
return "indexed_alpha";
break;
case V2Image::IMAGE_FORMAT_BC1:
return "bc1";
break;
case V2Image::IMAGE_FORMAT_BC2:
return "bc2";
break;
case V2Image::IMAGE_FORMAT_BC3:
return "bc3";
break;
case V2Image::IMAGE_FORMAT_BC4:
return "bc4";
break;
case V2Image::IMAGE_FORMAT_BC5:
return "bc5";
break;
case V2Image::IMAGE_FORMAT_CUSTOM:
return "custom custom_size=" + itos(p_img_size) + "";
break;
default:
return "UNKNOWN_IMAGE_FORMAT";
}
}
// V4 removed PVRTC, need to convert enums
V2Image::Format ImageEnumCompat::convert_image_format_enum_v4_to_v2(Image::Format p_format) {
switch (p_format) {
// convert old image format types to new ones
case Image::FORMAT_L8:
return V2Image::IMAGE_FORMAT_GRAYSCALE;
case Image::FORMAT_LA8:
return V2Image::IMAGE_FORMAT_GRAYSCALE_ALPHA;
case Image::FORMAT_RGB8:
return V2Image::IMAGE_FORMAT_RGB;
case Image::FORMAT_RGBA8:
return V2Image::IMAGE_FORMAT_RGBA;
case Image::FORMAT_DXT1:
return V2Image::IMAGE_FORMAT_BC1;
case Image::FORMAT_DXT3:
return V2Image::IMAGE_FORMAT_BC2;
case Image::FORMAT_DXT5:
return V2Image::IMAGE_FORMAT_BC3;
case Image::FORMAT_RGTC_R:
return V2Image::IMAGE_FORMAT_BC4;
case Image::FORMAT_RGTC_RG:
return V2Image::IMAGE_FORMAT_BC5;
case Image::FORMAT_ETC:
return V2Image::IMAGE_FORMAT_ETC;
default: {
}
}
return V2Image::IMAGE_FORMAT_V2_MAX;
}
Image::Format ImageEnumCompat::convert_image_format_enum_v2_to_v4(V2Image::Format p_format) {
switch (p_format) {
// convert old image format types to new ones
case V2Image::IMAGE_FORMAT_GRAYSCALE:
return Image::FORMAT_L8;
case V2Image::IMAGE_FORMAT_GRAYSCALE_ALPHA:
return Image::FORMAT_LA8;
case V2Image::IMAGE_FORMAT_RGB:
return Image::FORMAT_RGB8;
case V2Image::IMAGE_FORMAT_RGBA:
return Image::FORMAT_RGBA8;
case V2Image::IMAGE_FORMAT_BC1:
return Image::FORMAT_DXT1;
case V2Image::IMAGE_FORMAT_BC2:
return Image::FORMAT_DXT3;
case V2Image::IMAGE_FORMAT_BC3:
return Image::FORMAT_DXT5;
case V2Image::IMAGE_FORMAT_BC4:
return Image::FORMAT_RGTC_R;
case V2Image::IMAGE_FORMAT_BC5:
return Image::FORMAT_RGTC_RG;
case V2Image::IMAGE_FORMAT_ETC:
return Image::FORMAT_ETC;
// If this is a deprecated or unsupported format...
default: {
}
}
return Image::FORMAT_MAX;
}
Image::Format ImageEnumCompat::convert_image_format_enum_v3_to_v4(V3Image::Format fmt) {
// V4 removed
if (Image::Format(fmt) <= Image::Format::FORMAT_BPTC_RGBFU) {
return Image::Format(fmt);
}
// They removed four PVRTC enum values after BPTC_RGBFU, so just subtract 4
if (fmt >= V3Image::Format::FORMAT_ETC && fmt < V3Image::Format::FORMAT_MAX) {
return Image::Format(fmt - 4);
}
// If this is an invalid value, return FORMAT_MAX
return Image::FORMAT_MAX;
}