-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYGOFM-BGEx.cpp
729 lines (592 loc) · 21.4 KB
/
YGOFM-BGEx.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
// Yu-Gi-Oh! Forbidden Memories background image extractor
// by Xan / Tenjoin
// TODO - add other versions
// TODO - maybe add support for LBA calculation of other content
// TODO - maybe add support for repacking
#include <iostream>
#include <string>
#include "DDS.h"
//
// LBAs START
//
// based on SLUS-01411, change accordingly for your game
// these were ripped from the function 0x8002DF2C in the exe of SLUS-01411
constexpr unsigned int backgroundsLBA_allstart = 0x21D5;
constexpr unsigned int backgroundsLBA_start_0 = 0;
constexpr unsigned int backgroundsLBA_size_0 = 0x21;
constexpr unsigned int backgroundsLBA_start_1 = 0x672;
constexpr unsigned int backgroundsLBA_size_1 = 0x51;
constexpr unsigned int backgroundsLBA_start_2 = 0x13BC;
constexpr unsigned int backgroundsLBA_size_2 = 0x71;
unsigned long calclba(int BGindex, unsigned long &out_size, int &out_type)
{
int v2;
int v3;
int sizeLBA = backgroundsLBA_size_0;
int startLBA = backgroundsLBA_start_0;
v2 = 10 * ((BGindex >> 4) & 0xF) + (BGindex & 0xF);
v3 = BGindex >> 8;
switch (v3)
{
case 2:
sizeLBA = backgroundsLBA_size_2;
startLBA = backgroundsLBA_start_2;
break;
case 1:
sizeLBA = backgroundsLBA_size_1;
startLBA = backgroundsLBA_start_1;
break;
}
out_size = sizeLBA;
out_type = v3;
return startLBA + v2 * sizeLBA + backgroundsLBA_allstart;
}
//
// LBAs END
//
void DecodePS1ImageP8(uint8_t* inIndicies, uint16_t* inPalette, uint32_t* outARGB, size_t size, bool bForceBlackTransparency)
{
for (int i = 0; i < size; i++)
{
uint16_t color = inPalette[inIndicies[i]];
uint32_t rgba = 0;
if ((color & 0x7FFF) == 0)
{
if ((color & 0x8000) || bForceBlackTransparency)
rgba = 0;
else
rgba = 0xFF000000;
}
else
{
uint8_t r = color & 0x1F;
uint8_t g = (color & 0x3E0) >> 5;
uint8_t b = (color & 0x7C00) >> 10;
float fB = (float)b / 31.0f;
float fG = (float)g / 31.0f;
float fR = (float)r / 31.0f;
uint8_t b8 = (uint8_t)(fB * 255.0f);
uint8_t g8 = (uint8_t)(fG * 255.0f);
uint8_t r8 = (uint8_t)(fR * 255.0f);
uint8_t a8 = 0xFF;
if ((color & 0x8000))
{
a8 = (r8 + g8 + b8) / 3;
}
rgba |= b8 | (g8 << 8) | (r8 << 16) | (a8 << 24);
}
outARGB[i] = rgba;
}
}
void DecodePS1ImageP4(uint8_t* inIndicies, uint16_t* inPalette, uint32_t* outARGB, size_t size, bool bForceBlackTransparency)
{
int j = 0;
for (int i = 0; i < size; i++)
{
uint8_t index = inIndicies[j];
// every other time get other 4 bits and increment
if (i & 1)
{
index = (index & 0xF0) >> 4;
j++;
}
else
index &= 0xF;
uint16_t color = inPalette[index];
uint32_t rgba = 0;
if ((color & 0x7FFF) == 0)
{
if ((color & 0x8000) || bForceBlackTransparency)
rgba = 0;
else
rgba = 0xFF000000;
}
else
{
uint8_t r = color & 0x1F;
uint8_t g = (color & 0x3E0) >> 5;
uint8_t b = (color & 0x7C00) >> 10;
float fB = (float)b / 31.0f;
float fG = (float)g / 31.0f;
float fR = (float)r / 31.0f;
uint8_t b8 = (uint8_t)(fB * 255.0f);
uint8_t g8 = (uint8_t)(fG * 255.0f);
uint8_t r8 = (uint8_t)(fR * 255.0f);
uint8_t a8 = 0xFF;
if ((color & 0x8000))
{
a8 = (r8 + g8 + b8) / 3;
}
rgba |= b8 | (g8 << 8) | (r8 << 16) | (a8 << 24);
}
outARGB[i] = rgba;
}
}
// Untiles a 128x512 buffer to a 320x160 image
void* UntileImage(void* inBuffer, unsigned int imgUntileWidth, unsigned int imgUntileHeight, size_t imgSize)
{
// parts in order of visual presentation in the tiled version
// 1 - 128x160
// 5 - 128x96 -- ignored
// 2 - 128x160
// 3 - 64x80, 4 - 64x80
// 6 - 128x16 -- ignored
uintptr_t cursor = 0;
uint32_t* output_colors = (uint32_t*)(inBuffer);
size_t imgUntileSize = imgUntileWidth * imgUntileHeight;
constexpr unsigned int part1width = 128;
constexpr unsigned int part1height = 160;
constexpr unsigned int part1size = (part1width * part1height);
void* part1 = malloc(part1size * 4);
memcpy(part1, inBuffer, part1size * 4);
uint32_t* rgba_part1 = (uint32_t*)(part1);
constexpr unsigned int part2width = 128;
constexpr unsigned int part2height = 160;
constexpr unsigned int part2size = (part2width * part2height);
uintptr_t part2start = imgSize / 2;
void* part2 = malloc(part2size * 4);
memcpy(part2, &(output_colors[part2start]), part2size * 4);
uint32_t* rgba_part2 = (uint32_t*)(part2);
constexpr unsigned int part3width = 64;
constexpr unsigned int part3height = 80;
constexpr unsigned int part3size = (part3width * part3height);
uintptr_t part3start = part2start + part2size;
void* part3 = malloc(part3size * 4);
uint32_t* rgba_part3 = (uint32_t*)(part3);
constexpr unsigned int part4width = 64;
constexpr unsigned int part4height = 80;
constexpr unsigned int part4size = (part4width * part4height);
uintptr_t part4start = part3start + (part3width);
void* part4 = malloc(part4size * 4);
uint32_t* rgba_part4 = (uint32_t*)(part4);
// copy half width images
cursor = part3start;
for (int i = 0; i < part3size; i++)
{
rgba_part3[i] = output_colors[(cursor)];
cursor++;
if (!(cursor % part3width))
cursor += part4width;
}
cursor = part4start;
for (int i = 0; i < part4size; i++)
{
rgba_part4[i] = output_colors[(cursor)];
cursor++;
if (!(cursor % (part3width + part4width)))
cursor += part3width;
}
// stitch image together
void* new_output_buffer = malloc(imgUntileSize * 4);
uintptr_t new_output_buffer_ptr = (uintptr_t)new_output_buffer;
uint32_t* rgba_new = (uint32_t*)(new_output_buffer);
unsigned int part3heightsize = part3height * imgUntileWidth;
int p1 = 0;
int p2 = 0;
int p3 = 0;
int p4 = 0;
memset(new_output_buffer, 0, imgUntileSize * 4);
for (int i = 0; i < imgUntileSize; i++)
{
int pos = i % imgUntileWidth;
if (pos < part1width)
{
rgba_new[i] = rgba_part1[p1];
p1++;
}
if ((pos >= (part1width)) && (pos < (part1width + part2width)))
{
rgba_new[i] = rgba_part2[p2];
p2++;
}
if (i < part3heightsize)
{
if ((pos >= (part1width + part2width)) && (pos < (part1width + part2width + part3width)))
{
rgba_new[i] = rgba_part3[p3];
p3++;
}
}
else
{
if ((pos >= (part1width + part2width)) && (pos < (part1width + part2width + part4width)))
{
rgba_new[i] = rgba_part4[p4];
p4++;
}
}
}
free(part4);
free(part3);
free(part2);
free(part1);
free(inBuffer);
return new_output_buffer;
}
// Untiles a 256x256 buffer to a 320x160 image
void* UntileImage256(void* inBuffer, unsigned int imgUntileWidth, unsigned int imgUntileHeight, size_t imgSize)
{
// parts in order of visual presentation in the tiled version (from left to right)
// 1 - 256x160
// 4 - 128x96 -- ignored, 2 - 64x80, 3 - 64x80
// 5 - 128x16 -- ignored
uintptr_t cursor = 0;
uint32_t* output_colors = (uint32_t*)(inBuffer);
size_t imgUntileSize = imgUntileWidth * imgUntileHeight;
constexpr unsigned int part1width = 256;
constexpr unsigned int part1height = 160;
constexpr unsigned int part1size = (part1width * part1height);
void* part1 = malloc(part1size * 4);
memcpy(part1, inBuffer, part1size * 4);
uint32_t* rgba_part1 = (uint32_t*)(part1);
constexpr unsigned int part4width = 128;
constexpr unsigned int part2width = 64;
constexpr unsigned int part2height = 80;
constexpr unsigned int part2size = (part2width * part2height);
uintptr_t part2start = (part1height * part1width) + part4width;
void* part2 = malloc(part2size * 4);
uint32_t* rgba_part2 = (uint32_t*)(part2);
constexpr unsigned int part3width = 64;
constexpr unsigned int part3height = 80;
constexpr unsigned int part3size = (part3width * part3height);
uintptr_t part3start = part2start + part2width;
void* part3 = malloc(part3size * 4);
uint32_t* rgba_part3 = (uint32_t*)(part3);
cursor = part2start;
for (int i = 0; i < part2size; i++)
{
rgba_part2[i] = output_colors[(cursor)];
cursor++;
if (!(cursor % part2width))
cursor += part3width + part4width;
}
cursor = part3start;
for (int i = 0; i < part3size; i++)
{
rgba_part3[i] = output_colors[(cursor)];
cursor++;
if (!(cursor % part3width))
cursor += part4width + part2width;
}
// stitch image together
void* new_output_buffer = malloc(imgUntileSize * 4);
uintptr_t new_output_buffer_ptr = (uintptr_t)new_output_buffer;
uint32_t* rgba_new = (uint32_t*)(new_output_buffer);
unsigned int part2heightsize = part2height * imgUntileWidth;
int p1 = 0;
int p2 = 0;
int p3 = 0;
memset(new_output_buffer, 0, imgUntileSize * 4);
for (int i = 0; i < imgUntileSize; i++)
{
int pos = i % imgUntileWidth;
if (pos < part1width)
{
rgba_new[i] = rgba_part1[p1];
p1++;
}
if (i < part2heightsize)
{
if ((pos >= (part1width)) && (pos < (part1width + part2width)))
{
rgba_new[i] = rgba_part2[p2];
p2++;
}
}
else
{
if ((pos >= (part1width)) && (pos < (part1width + part3width)))
{
rgba_new[i] = rgba_part3[p3];
p3++;
}
}
}
free(part3);
free(part2);
free(part1);
free(inBuffer);
return new_output_buffer;
}
// Untiles a 128x512 buffer to a 256x256 image
void* UntileImage256x256(void* inBuffer, unsigned int imgUntileWidth, unsigned int imgUntileHeight, size_t imgSize)
{
// parts in order of visual presentation in the tiled version
// 1 - 128x256
// 2 - 128x256
uintptr_t cursor = 0;
uint32_t* output_colors = (uint32_t*)(inBuffer);
size_t imgUntileSize = imgUntileWidth * imgUntileHeight;
constexpr unsigned int part1width = 128;
constexpr unsigned int part1height = 256;
constexpr unsigned int part1size = (part1width * part1height);
void* part1 = malloc(part1size * 4);
memcpy(part1, inBuffer, part1size * 4);
uint32_t* rgba_part1 = (uint32_t*)(part1);
constexpr unsigned int part2width = 128;
constexpr unsigned int part2height = 256;
constexpr unsigned int part2size = (part2width * part2height);
uintptr_t part2start = imgSize / 2;
void* part2 = malloc(part2size * 4);
memcpy(part2, &(output_colors[part2start]), part2size * 4);
uint32_t* rgba_part2 = (uint32_t*)(part2);
// stitch image together
void* new_output_buffer = malloc(imgUntileSize * 4);
uintptr_t new_output_buffer_ptr = (uintptr_t)new_output_buffer;
uint32_t* rgba_new = (uint32_t*)(new_output_buffer);
int p1 = 0;
int p2 = 0;
memset(new_output_buffer, 0, imgUntileSize * 4);
for (int i = 0; i < imgUntileSize; i++)
{
int pos = i % imgUntileWidth;
if (pos < part1width)
{
rgba_new[i] = rgba_part1[p1];
p1++;
}
if ((pos >= (part1width)) && (pos < (part1width + part2width)))
{
rgba_new[i] = rgba_part2[p2];
p2++;
}
}
free(part2);
free(part1);
free(inBuffer);
return new_output_buffer;
}
void WriteImage(std::string filename, int index, int subindex, void* buffer, unsigned int width, unsigned int height)
{
// create dds
struct DirectX::DDS_HEADER ddshs = { 0 };
struct DirectX::DDS_PIXELFORMAT ddspfs = { 0 };
ddshs.dwSize = 124;
ddshs.dwFlags = 0x21007;
ddshs.dwWidth = width;
ddshs.dwHeight = height;
ddshs.dwMipMapCount = 0;
ddspfs.dwSize = 32;
ddspfs.dwFlags = 0x41;
ddspfs.dwRGBBitCount = 0x20;
ddspfs.dwRBitMask = 0xFF0000;
ddspfs.dwGBitMask = 0xFF00;
ddspfs.dwBBitMask = 0xFF;
ddspfs.dwABitMask = 0xFF000000;
ddshs.dwCaps = 0x40100A;
ddshs.ddspf = ddspfs;
constexpr unsigned int DDSMagic = 0x20534444;
size_t writeSize = (width * height) * sizeof(uint32_t);
std::string outFilename = filename + "_" + std::to_string(index) + "_" + std::to_string(subindex) + ".out.dds";
std::cout << "Writing: " << outFilename << '\n';
FILE* fout = fopen(outFilename.c_str(), "wb");
if (!fout)
{
std::cout << "ERROR: couldn't open file for writing: " << outFilename << '\n';
perror("ERROR");
return;
}
fwrite(&DDSMagic, 4, 1, fout);
fwrite(&ddshs, sizeof(ddshs), 1, fout);
fwrite(buffer, sizeof(uint8_t), writeSize, fout);
fclose(fout);
}
// Starts the extraction process of background images
// filename - filename of WA_MRG.MRG
// index - image index
// bUntile - untile flag
// TransparencyMode - 0 = keep original data, 1 = black is transparent for subimages 0 on type 1 and 2 on type 2, 2 = black is always transparent
void ExtractBGToDDS(std::string filename, int index, bool bUntile = true, uint32_t TransparencyMode = 1)
{
std::cout << "Opening: " << filename << '\n';
FILE* fin = fopen(filename.c_str(), "rb");
if (!fin)
{
std::cout << "ERROR: couldn't open file for reading: " << filename << '\n';
perror("ERROR");
return;
}
unsigned long lbasize = 0;
unsigned long size = 0;
int type = 0;
unsigned long lba = calclba(index, lbasize, type);
unsigned int imgWidth = 0;
unsigned int imgHeight = 0;
unsigned int imgSize = 0;
unsigned int imgWriteSize = 0;
constexpr unsigned int imgUntileWidth = 320;
constexpr unsigned int imgUntileHeight = 160;
constexpr unsigned int imgUntileSize = imgUntileWidth * imgUntileHeight;
constexpr unsigned int imgUntileWidth2 = 256;
constexpr unsigned int imgUntileHeight2 = 256;
constexpr unsigned int imgUntileSize2 = imgUntileWidth2 * imgUntileHeight2;
constexpr unsigned int imgWriteSize2 = imgUntileSize2 * 4;
constexpr unsigned int simgWidth = 256;
constexpr unsigned int simgHeight = 256;
constexpr unsigned int simgSize = simgWidth * simgHeight;
constexpr unsigned int simgHalfSize = simgSize / 2;
constexpr unsigned int simgUntileWidth = 320;
constexpr unsigned int simgUntileHeight = 160;
constexpr unsigned int simgUntileSize = simgUntileWidth * simgUntileHeight;
unsigned int simgWriteSize = 0;
unsigned int imgCount = 1;
unsigned int simgCount = 0;
constexpr unsigned int palleteSize256 = 256 * sizeof(uint16_t);
constexpr unsigned int palleteSize16 = 16 * sizeof(uint16_t);
switch (type)
{
case 2:
imgCount = 3;
simgCount = 1;
simgWriteSize = simgSize * 4;
if (bUntile)
simgWriteSize = simgUntileSize * 4;
imgWidth = 128;
imgHeight = 512;
break;
case 1:
imgCount = 2;
simgCount = 1;
simgWriteSize = simgSize * 4;
if (bUntile)
simgWriteSize = simgUntileSize * 4;
imgWidth = 128;
imgHeight = 512;
break;
default:
imgWidth = 128;
imgHeight = 512;
break;
}
imgSize = imgWidth * imgHeight;
imgWriteSize = imgSize * 4;
if (bUntile) imgWriteSize = imgUntileSize * 4;
size = lbasize * 0x800;
std::cout <<
"LBA: 0x" << std::uppercase << std::hex << lba << "\n"
"SizeLBA: 0x" << std::uppercase << std::hex << lbasize << "\n"
"Offset: 0x" << std::uppercase << std::hex << lba * 0x800 << "\n"
"Size: 0x" << std::uppercase << std::hex << size << "\n";
void* input_buffer = malloc(size);
fseek(fin, lba * 0x800, SEEK_SET);
fread(input_buffer, size, 1, fin);
fclose(fin);
// extract 320x160 images
for (int c = 0; c < imgCount; c++)
{
uint16_t* palette = nullptr;
uint8_t* indicies = (uint8_t*)((uintptr_t)input_buffer + (imgSize * c));
if (type == 1)
{
palette = (uint16_t*)((uintptr_t)input_buffer + (imgSize * imgCount) + (simgHalfSize * simgCount) + (palleteSize256 * c));
}
else if (type == 2)
{
if (c == 2) // 3rd image has its own palette
palette = (uint16_t*)((uintptr_t)input_buffer + (imgSize * imgCount) + (simgHalfSize * simgCount) + (palleteSize256 * (c - 1)));
else
palette = (uint16_t*)((uintptr_t)input_buffer + (imgSize * imgCount) + (simgHalfSize * simgCount));
}
else
{
palette = (uint16_t*)((uintptr_t)input_buffer + (imgSize * imgCount) + (palleteSize256 * c));
}
void* output_buffer = malloc(imgSize * 4);
bool bTransparencyFlag = false;
if (TransparencyMode == 1)
bTransparencyFlag = ((c == 0) && ((type == 1)) || (c == 2) && ((type == 2)));
if (TransparencyMode == 2)
bTransparencyFlag = true;
DecodePS1ImageP8(indicies, palette, (uint32_t*)(output_buffer), imgSize, bTransparencyFlag);
if (bUntile)
{
if (type == 2)
{
switch (c)
{
case 2:
output_buffer = UntileImage(output_buffer, imgUntileWidth, imgUntileHeight, imgSize);
WriteImage(filename, index, c, output_buffer, imgUntileWidth, imgUntileHeight);
break;
case 1:
output_buffer = UntileImage256x256(output_buffer, imgUntileWidth2, imgUntileHeight2, imgSize);
WriteImage(filename, index, c, output_buffer, imgUntileWidth2, imgUntileHeight2);
break;
case 0:
output_buffer = UntileImage256x256(output_buffer, imgUntileWidth2, imgUntileHeight2, imgSize);
WriteImage(filename, index, c, output_buffer, imgUntileWidth2, imgUntileHeight2);
break;
default:
break;
}
}
else
{
output_buffer = UntileImage(output_buffer, imgUntileWidth, imgUntileHeight, imgSize);
WriteImage(filename, index, c, output_buffer, imgUntileWidth, imgUntileHeight);
}
}
else
WriteImage(filename, index, c, output_buffer, imgWidth, imgHeight);
free(output_buffer);
}
// extract secondary images
if (type)
{
for (int c = 0; c < simgCount; c++)
{
uint16_t* palette = (uint16_t*)((uintptr_t)input_buffer + (imgSize * imgCount) + (simgHalfSize * simgCount) + (palleteSize256 * imgCount) + (palleteSize16 * c));
if (type == 1)
{
palette = (uint16_t*)((uintptr_t)input_buffer + (imgSize * imgCount) + (simgHalfSize * simgCount) + (palleteSize256 * imgCount) + (palleteSize16 * c));
}
else if (type == 2)
{
palette = (uint16_t*)((uintptr_t)input_buffer + (imgSize * imgCount) + (simgHalfSize * simgCount) + (palleteSize16 * c));
}
uint8_t* indicies = (uint8_t*)((uintptr_t)input_buffer + (imgSize * imgCount) + (simgHalfSize * c));
void* output_buffer = malloc(simgSize * 4);
bool bTransparencyFlag = false;
if (TransparencyMode)
bTransparencyFlag = true;
DecodePS1ImageP4(indicies, palette, (uint32_t*)(output_buffer), simgSize, true);
if (bUntile)
{
output_buffer = UntileImage256(output_buffer, simgUntileWidth, simgUntileHeight, simgSize);
WriteImage(filename, index, c + imgCount, output_buffer, simgUntileWidth, simgUntileHeight);
}
else
WriteImage(filename, index, c + imgCount, output_buffer, simgWidth, simgHeight);
free(output_buffer);
}
}
free(input_buffer);
}
int main(int argc, char* argv[])
{
if (argc < 3)
{
std::cout
<< "USAGE: " << argv[0] << " WA_MRG_path index [untile [transparency]]\n"
<< "index = image index\n"
<< "untile = enable/disable untiling (0/1) (1 = default)\n"
<< "transparency = transparency mode (0 = keep original data, black is transparent for subimages 0 on type 1 and 2 on type 2 (default), 2 = black is always transparent)\n";
return -1;
}
bool bUntile = true;
uint32_t TransparencyMode = 1;
if (argc >= 4)
{
bUntile = std::stoi(argv[3]) != 0;
}
if (argc >= 5)
{
TransparencyMode = std::stoi(argv[argc-1]);
}
if (bUntile)
std::cout << "Untiling enabled!\n";
else
std::cout << "Untiling disabled!\n";
ExtractBGToDDS(argv[1], std::stoi(argv[2]), bUntile, TransparencyMode);
return 0;
}