-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool.cpp
101 lines (77 loc) · 1.89 KB
/
tool.cpp
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
using namespace std;
void GetInt(int& value, string stream)
{
char temp[40];
sscanf(stream.c_str(), "%s %s %d", temp, temp, &value);
}
void GetCArray(const char* file_name, string& c_array, int& width, int& height)
{
fstream file;
file.open(file_name, std::ios::in);
if (!file)
{
cout << "Error :: Could'nt open file to Read : " << file_name;
return;
}
string temp;
//get width
getline(file, temp);
GetInt(width, temp);
//get height
getline(file, temp);
GetInt(height, temp);
//Skip the 3rd line
getline(file, temp);
//read the c_array from the file
while (file)
{
getline(file, temp);
c_array += "\n" + temp;
}
file.close();
c_array.pop_back();
c_array.pop_back();
}
void WriteToFile(const char* file_name, char* payload){
ofstream file;
file.open(file_name);
if (!file)
{
cout<<"Error :: Could'nt open file to Write : " << file_name << std::endl;
return;
}
file << payload;
file.close();
}
int main()
{
string fileFormat =
"#include <stdint.h>\n"
"\nstatic const struct\n"
"{\n"
" uint16_t width;\n"
" uint16_t height;\n"
" uint8_t pixel_data[];\n"
"}\n"
"apertus_logo_part_1 = {\n"
"%d, %d, \n"
" {%s}\n"
",apertus_logo_part_2 = { \n"
"%d, %d, \n"
" {%s};";
string c_array_1, c_array_2;
int width_1, height_1, width_2, height_2;
GetCArray("apertus_logo_part_1.xbm", c_array_1, width_1, height_1);
GetCArray("apertus_logo_part_2.xbm", c_array_2, width_2, height_2);
int final_length = snprintf(NULL, 0, fileFormat.c_str(), width_1, height_1,
c_array_1.c_str(), width_2, height_2, c_array_2.c_str());
char* cstr = new char[final_length + 1];
sprintf(cstr, fileFormat.c_str(), width_1, height_1, c_array_1.c_str(),
width_2, height_2, c_array_2.c_str());
WriteToFile("ApertusLogo.h", cstr);
return 0;
}