Skip to content

Commit 960df9d

Browse files
committed
- adding DriverImageTool project, sky extraction support
1 parent 619a633 commit 960df9d

4 files changed

Lines changed: 149 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ DriverLevelTool/bin/*
5252
DriverLevelTool/obj/*
5353
DriverSoundTool/bin/*
5454
DriverSoundTool/obj/*
55+
ImageUnpackTool/bin/*
56+
ImageUnpackTool/obj/*
5557
LEVELS/*

DriverImageTool/image_tool.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include <math.h>
2+
3+
#include <malloc.h>
4+
#include "core/VirtualStream.h"
5+
#include "core/cmdlib.h"
6+
#include "math/dktypes.h"
7+
#include "util/image.h"
8+
#include "util/util.h"
9+
10+
struct RECT16
11+
{
12+
short x, y, w, h;
13+
};
14+
15+
const int SKY_CLUT_START_Y = 252;
16+
const int SKY_SIZE_W = 128 / 4;
17+
const int SKY_SIZE_H = 84;
18+
19+
void CopyTpageImage(ushort* tp_src, ushort* dst, int x, int y, int dst_w, int dst_h)
20+
{
21+
ushort* src = tp_src + x + 128 * y;
22+
23+
for (int i = 0; i < dst_h; i++)
24+
{
25+
memcpy(dst, src, dst_w * sizeof(short));
26+
dst += dst_w;
27+
src += 128;
28+
}
29+
}
30+
31+
void ExportSkyImage(const char* skyFileName, ubyte* data, int x_idx, int y_idx, int sky_id, int n)
32+
{
33+
ubyte imageCopy[SKY_SIZE_W * SKY_SIZE_H];
34+
ushort imageClut[16];
35+
36+
CopyTpageImage((ushort*)data, (ushort*)imageCopy, x_idx * SKY_SIZE_W, y_idx * SKY_SIZE_H, SKY_SIZE_W / 2, SKY_SIZE_H);
37+
CopyTpageImage((ushort*)data, (ushort*)imageClut, x_idx * 16, SKY_CLUT_START_Y + y_idx, 16, 1);
38+
39+
SaveTIM_4bit(varargs("%s_%d_%d.TIM", skyFileName, sky_id, n),
40+
imageCopy, SKY_SIZE_W * SKY_SIZE_H, 0, 0, SKY_SIZE_W*2, SKY_SIZE_H, (ubyte*)imageClut, 1);
41+
}
42+
43+
void ConvertSky(const char* skyFileName)
44+
{
45+
FILE* fp = fopen(skyFileName, "rb");
46+
if(!fp)
47+
{
48+
MsgError("Unable to open '%s'\n", skyFileName);
49+
return;
50+
}
51+
52+
MsgInfo("Converting '%s' to separate TIM files...", skyFileName);
53+
54+
fseek(fp, 0, SEEK_END);
55+
int size = ftell(fp);
56+
fseek(fp, 0, SEEK_SET);
57+
58+
ubyte* data = (ubyte*)malloc(size);
59+
60+
fread(data, size, 1, fp);
61+
fclose(fp);
62+
63+
const int OFFSET_STEP = 0x10000;
64+
65+
for(int i = 0; i < 5; i++)
66+
{
67+
int n = 0;
68+
ubyte* skyImage = data + i * OFFSET_STEP;
69+
70+
for (int y = 0; y < 3; y++)
71+
{
72+
for (int x = 0; x < 4; x++, n++)
73+
ExportSkyImage(skyFileName, skyImage, x, y, i, n);
74+
}
75+
}
76+
77+
MsgInfo("Done!");
78+
}
79+
80+
//-----------------------------------------------------
81+
82+
void PrintCommandLineArguments()
83+
{
84+
MsgInfo("Example usage:\n");
85+
MsgInfo("\tDriverImageTool -sky2tim SKY0.RAW\n");
86+
}
87+
88+
int main(int argc, char** argv)
89+
{
90+
#ifdef _WIN32
91+
Install_ConsoleSpewFunction();
92+
#endif
93+
94+
Msg("---------------\nDriverImageTool - PSX Driver image utilities\n---------------\n\n");
95+
96+
if (argc <= 1)
97+
{
98+
PrintCommandLineArguments();
99+
return -1;
100+
}
101+
102+
for (int i = 0; i < argc; i++)
103+
{
104+
if (!stricmp(argv[i], "-sky2tim"))
105+
{
106+
if (i + 1 <= argc)
107+
ConvertSky(argv[i + 1]);
108+
else
109+
MsgWarning("-sky2tim must have an argument!");
110+
}
111+
}
112+
113+
return 0;
114+
}

DriverImageTool/premake5.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- premake5.lua
2+
3+
project "DriverImageTool"
4+
kind "ConsoleApp"
5+
language "C++"
6+
compileas "C++"
7+
targetdir "bin/%{cfg.buildcfg}"
8+
9+
files {
10+
"**.cpp",
11+
"**.h",
12+
}
13+
14+
filter "system:linux"
15+
buildoptions {
16+
"-Wno-narrowing",
17+
"-fpermissive",
18+
"-m32"
19+
}
20+
21+
linkoptions {
22+
"-m32"
23+
}
24+
25+
filter "configurations:Debug"
26+
targetsuffix "_dbg"
27+
symbols "On"
28+
29+
filter "configurations:Release"
30+
optimize "Full"
31+

premake5.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ workspace "OpenDriver2Tools"
3939
}
4040

4141
dofile("DriverLevelTool/premake5.lua")
42-
dofile("DriverSoundTool/premake5.lua")
42+
dofile("DriverSoundTool/premake5.lua")
43+
dofile("DriverImageTool/premake5.lua")

0 commit comments

Comments
 (0)