about summary refs log tree commit diff
path: root/trackinggenerator/main.cpp
blob: e63f9ce48495dac9d4dd6a320e296cd46e6fbcef (plain)
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
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{
	if (argc != 2)
	{
		cout << "Usage: bla <infile.tga>" << endl;
		return -1;
	}

	ifstream file(argv[1]);

	if (!file)
	{
		cout << "No such file..." << endl;
		return -1;
	}

	unsigned short headers[9];

	file.read((char *)headers, 18);

	int width = headers[6];
	int height = headers[7];

	const int charsx = 16;
	const int charsy = 16;
	const int charWidth = width / charsx;
	const int charHeight = height / charsy;

	char *data = new char[width * height * 4];

	file.read(data, width * height * 4);
	
    int startTable[256] = {0};
	int endTable[256] = {0};

    for (int i = 0; i < charsy; i++)
        for (int j = 0; j < charsx; j++)
        {
            bool done = false;

            for (int x = 0; x < charWidth && !done; ++x)
                for (int y = charHeight - 1; y >= 0; --y)
                {   
                    // check if alpha is != 0 
                    int tempX = j * charWidth + x;
                    int tempY = i * charHeight + y;
                    
                    int coordIndex = tempX + tempY * width;
                    
                    if (data[4 * coordIndex + 3] != 0)
                    {   
                        // if it is, save the x-coord to table and go to next character
                        startTable[j + i * charsx] = x;
                        done = true;
                    }
                }


			done = false;
            for (int x = charWidth - 1; x >= 0 && !done; --x)
                for (int y = charHeight - 1; y >= 0; --y)
                {
                    // check if alpha is != 0
                    int tempX = j * charWidth + x;
                    int tempY = i * charHeight + y;

                    int coordIndex = tempX + tempY * width;

                    if (data[4 * coordIndex + 3] != 0)
                    {
                        // if it is, save the x-coord to table and go to next character
                        endTable[j + i * charsx] = x;
                        done = true;
                    }
                }
        }

    delete[] data;

    cout << "float CharStartTable[] =" << endl << '{' << endl << '\t';

    for (int i = 0; i < 256; i++)
    {
        cout << startTable[i] / float(charWidth) << ", ";
        if (!((i + 1) % 16))
            cout << endl << '\t';
    }

    cout << endl << "};" << endl;

    cout << "float CharEndTable[] =" << endl << '{' << endl << '\t';

    for (int i = 0; i < 256; i++)
    {
        cout << endTable[i] / float(charWidth) << ", ";
        if (!((i + 1) % 16))
            cout << endl << '\t';
    }

    cout << endl << "};" << endl;

        
    cout << charWidth << 'x' << charHeight << endl;
}