~ubuntu-branches/ubuntu/trusty/teeworlds/trusty-updates

« back to all changes in this revision

Viewing changes to src/trackinggenerator/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jack Coulter
  • Date: 2008-04-13 18:48:12 UTC
  • Revision ID: james.westby@ubuntu.com-20080413184812-efc80waq2er6p1bs
Tags: upstream-0.4.2
ImportĀ upstreamĀ versionĀ 0.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
 
2
#include <iostream>
 
3
#include <fstream>
 
4
 
 
5
using namespace std;
 
6
 
 
7
int main(int argc, char *argv[])
 
8
{
 
9
        if (argc != 2)
 
10
        {
 
11
                cout << "Usage: bla <infile.tga>" << endl;
 
12
                return -1;
 
13
        }
 
14
 
 
15
        ifstream file(argv[1]);
 
16
 
 
17
        if (!file)
 
18
        {
 
19
                cout << "No such file..." << endl;
 
20
                return -1;
 
21
        }
 
22
 
 
23
        unsigned short headers[9];
 
24
 
 
25
        file.read((char *)headers, 18);
 
26
 
 
27
        int width = headers[6];
 
28
        int height = headers[7];
 
29
 
 
30
        const int charsx = 16;
 
31
        const int charsy = 16;
 
32
        const int charWidth = width / charsx;
 
33
        const int charHeight = height / charsy;
 
34
 
 
35
        char *data = new char[width * height * 4];
 
36
 
 
37
        file.read(data, width * height * 4);
 
38
        
 
39
    int startTable[256] = {0};
 
40
        int endTable[256] = {0};
 
41
 
 
42
    for (int i = 0; i < charsy; i++)
 
43
        for (int j = 0; j < charsx; j++)
 
44
        {
 
45
            bool done = false;
 
46
 
 
47
            for (int x = 0; x < charWidth && !done; ++x)
 
48
                for (int y = charHeight - 1; y >= 0; --y)
 
49
                {   
 
50
                    // check if alpha is != 0 
 
51
                    int tempX = j * charWidth + x;
 
52
                    int tempY = i * charHeight + y;
 
53
                    
 
54
                    int coordIndex = tempX + tempY * width;
 
55
                    
 
56
                    if (data[4 * coordIndex + 3] != 0)
 
57
                    {   
 
58
                        // if it is, save the x-coord to table and go to next character
 
59
                        startTable[j + i * charsx] = x;
 
60
                        done = true;
 
61
                    }
 
62
                }
 
63
 
 
64
 
 
65
                        done = false;
 
66
            for (int x = charWidth - 1; x >= 0 && !done; --x)
 
67
                for (int y = charHeight - 1; y >= 0; --y)
 
68
                {
 
69
                    // check if alpha is != 0
 
70
                    int tempX = j * charWidth + x;
 
71
                    int tempY = i * charHeight + y;
 
72
 
 
73
                    int coordIndex = tempX + tempY * width;
 
74
 
 
75
                    if (data[4 * coordIndex + 3] != 0)
 
76
                    {
 
77
                        // if it is, save the x-coord to table and go to next character
 
78
                        endTable[j + i * charsx] = x;
 
79
                        done = true;
 
80
                    }
 
81
                }
 
82
        }
 
83
 
 
84
    delete[] data;
 
85
 
 
86
    cout << "float CharStartTable[] =" << endl << '{' << endl << '\t';
 
87
 
 
88
    for (int i = 0; i < 256; i++)
 
89
    {
 
90
        cout << startTable[i] / float(charWidth) << ", ";
 
91
        if (!((i + 1) % 16))
 
92
            cout << endl << '\t';
 
93
    }
 
94
 
 
95
    cout << endl << "};" << endl;
 
96
 
 
97
    cout << "float CharEndTable[] =" << endl << '{' << endl << '\t';
 
98
 
 
99
    for (int i = 0; i < 256; i++)
 
100
    {
 
101
        cout << endTable[i] / float(charWidth) << ", ";
 
102
        if (!((i + 1) % 16))
 
103
            cout << endl << '\t';
 
104
    }
 
105
 
 
106
    cout << endl << "};" << endl;
 
107
 
 
108
        
 
109
    cout << charWidth << 'x' << charHeight << endl;
 
110
}