1
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
7
int main(int argc, char *argv[])
11
cout << "Usage: bla <infile.tga>" << endl;
15
ifstream file(argv[1]);
19
cout << "No such file..." << endl;
23
unsigned short headers[9];
25
file.read((char *)headers, 18);
27
int width = headers[6];
28
int height = headers[7];
30
const int charsx = 16;
31
const int charsy = 16;
32
const int charWidth = width / charsx;
33
const int charHeight = height / charsy;
35
char *data = new char[width * height * 4];
37
file.read(data, width * height * 4);
39
int startTable[256] = {0};
40
int endTable[256] = {0};
42
for (int i = 0; i < charsy; i++)
43
for (int j = 0; j < charsx; j++)
47
for (int x = 0; x < charWidth && !done; ++x)
48
for (int y = charHeight - 1; y >= 0; --y)
50
// check if alpha is != 0
51
int tempX = j * charWidth + x;
52
int tempY = i * charHeight + y;
54
int coordIndex = tempX + tempY * width;
56
if (data[4 * coordIndex + 3] != 0)
58
// if it is, save the x-coord to table and go to next character
59
startTable[j + i * charsx] = x;
66
for (int x = charWidth - 1; x >= 0 && !done; --x)
67
for (int y = charHeight - 1; y >= 0; --y)
69
// check if alpha is != 0
70
int tempX = j * charWidth + x;
71
int tempY = i * charHeight + y;
73
int coordIndex = tempX + tempY * width;
75
if (data[4 * coordIndex + 3] != 0)
77
// if it is, save the x-coord to table and go to next character
78
endTable[j + i * charsx] = x;
86
cout << "float CharStartTable[] =" << endl << '{' << endl << '\t';
88
for (int i = 0; i < 256; i++)
90
cout << startTable[i] / float(charWidth) << ", ";
95
cout << endl << "};" << endl;
97
cout << "float CharEndTable[] =" << endl << '{' << endl << '\t';
99
for (int i = 0; i < 256; i++)
101
cout << endTable[i] / float(charWidth) << ", ";
103
cout << endl << '\t';
106
cout << endl << "};" << endl;
109
cout << charWidth << 'x' << charHeight << endl;