Skip to content

Commit b278ff8

Browse files
committed
- '-bg2tim' now extracts backgrounds properly
1 parent f96e790 commit b278ff8

1 file changed

Lines changed: 42 additions & 14 deletions

File tree

DriverImageTool/image_tool.cpp

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
#include "util/util.h"
99

1010
#include <string.h>
11-
#include "math/Vector.h"
11+
#include <nstd/String.hpp>
1212

13-
struct RECT16
14-
{
15-
short x, y, w, h;
16-
};
13+
#include "math/Vector.h"
1714

1815
const int SKY_CLUT_START_Y = 252;
1916
const int SKY_SIZE_W = 256 / 4;
@@ -166,7 +163,7 @@ void ConvertSky(const char* skyFileName, bool saveTGA)
166163
free(color_data);
167164
}
168165

169-
MsgInfo("Done!");
166+
MsgInfo("Done!\n");
170167
}
171168

172169
//-----------------------------------------------------
@@ -196,7 +193,7 @@ void ConvertBackgroundRaw(const char* filename, const char* extraFilename)
196193
return;
197194
}
198195

199-
MsgInfo("Converting background '%s' to separate TIM files...", filename);
196+
MsgInfo("Converting background '%s' to separate TIM files...\n", filename);
200197

201198
// read background file
202199
fseek(bgFp, 0, SEEK_END);
@@ -208,6 +205,38 @@ void ConvertBackgroundRaw(const char* filename, const char* extraFilename)
208205

209206
fclose(bgFp);
210207

208+
ubyte* imageClut = bgData + 11 * 0x8000;
209+
210+
// convert background image and store
211+
{
212+
ubyte timData[64*6 * 2 * 512];
213+
214+
int rect_w;
215+
int rect_h;
216+
rect_w = 64;
217+
rect_h = 256;
218+
219+
for (int i = 0; i < 6; i++)
220+
{
221+
ubyte* bgImagePiece = bgData + i * 0x8000;
222+
223+
int rect_y = i / 3;
224+
int rect_x = (i - (rect_y & 1) * 3) * 128;
225+
rect_y *= 256;
226+
227+
for (int y = 0; y < rect_h; y++)
228+
{
229+
for (int x = 0; x < rect_w * 2; x++)
230+
{
231+
timData[(rect_y + y) * 64 * 6 + rect_x + x] = bgImagePiece[y * 128 + x];
232+
}
233+
}
234+
}
235+
236+
SaveTIM_4bit(varargs("%s.TIM", filename),
237+
timData, 64 * 6 * 512, 0, 0, 384*2, 512, (ubyte*)imageClut, 1);
238+
}
239+
211240
// load extra file if specified
212241
if(extraFilename)
213242
{
@@ -219,7 +248,7 @@ void ConvertBackgroundRaw(const char* filename, const char* extraFilename)
219248
return;
220249
}
221250

222-
MsgInfo("Converting '%s' to separate TIM files...", extraFilename);
251+
MsgInfo("Converting '%s' to separate TIM files...\n", extraFilename);
223252

224253
fseek(fp, 0, SEEK_END);
225254
int size = ftell(fp);
@@ -230,21 +259,20 @@ void ConvertBackgroundRaw(const char* filename, const char* extraFilename)
230259
fread(data, size, 1, fp);
231260
fclose(fp);
232261

233-
const int OFFSET_STEP = 0x8000;
234-
235-
for (int i = 0; i < 10; i++)
262+
for (int i = 0; i < 16; i++)
236263
{
237-
ubyte* imageAddr = data + i * OFFSET_STEP;
264+
ubyte* imageAddr = data + i * 0x8000;
238265

239-
ExportExtraImage(extraFilename, imageAddr, bgData + 11*0x8000, i);
266+
if ((i * 0x8000) < size)
267+
ExportExtraImage(extraFilename, imageAddr, imageClut, i);
240268
}
241269

242270
free(data);
243271
}
244272

245273
free(bgData);
246274

247-
MsgInfo("Done!");
275+
MsgInfo("Done!\n");
248276
}
249277

250278
//-----------------------------------------------------

0 commit comments

Comments
 (0)