Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1769 yogev_ezra 1
#include 
2
#include 
3
#include 
4
#include 
5
#include 
6
#include "picture.h"
7
 
8
char str[1000], name[1000], *s;
9
int type;
10
 
11
int mx = 0, my = 0, slen;
12
BYTE *tex = 0;
13
 
14
inline void out_uc(unsigned char c, int &k)
15
{
16
	if (k < 0) {printf("\n\""); k = 0;}
17
	printf("\\x%02X", c);
18
	k++;
19
	if (k >= 20) {printf("\""); k = -1;}
20
}
21
 
22
inline void out_cl(int &k)
23
{
24
	if (k >= 0) {printf("\""); k = -1;}
25
}
26
 
27
inline void out_end(int &k)
28
{
29
	if (k == -10) return;
30
	if (type == 0) {out_uc(0, k); out_uc(255, k);}
31
	out_cl(k);
32
	printf(";\n\n");
33
	k = -10;
34
}
35
 
36
void del_last_space(char *s0)
37
{
38
	char *s1;
39
	for (s1 = s0; *s1; s1++)
40
	{
41
		if (!isspace(*s1)) s0 = s1 + 1;
42
	}
43
	*s0 = 0;
44
}
45
 
46
int main()
47
{
48
	BYTE *t0;
49
	int i, j, k, m, t, v;
50
//	randomize();
51
	srand(time(NULL));
52
	i = rand() + (rand() << 16);
53
	j = rand() + (rand() << 16);
54
	k = rand() + (rand() << 16);
55
	printf("#ifndef _INCLUDE_BITMAP_%08X_%08X_%08X__PICTURE_\n", i, j, k);
56
	printf("#define _INCLUDE_BITMAP_%08X_%08X_%08X__PICTURE_\n", i, j, k);
57
	strcpy(name, "bitmap_pictures");
58
	type = 0;
59
	k = -10;
60
	while (!feof(stdin))
61
	{
62
		memset(str, 0, sizeof(str));
63
		fgets(str, sizeof(str)-1, stdin);
64
		s = str;
65
		while (*s && isspace(*s)) s++;
66
		if (strncmp(s, "rem", 3) != 0) continue;
67
		s += 3;
68
		if (!isspace(*s)) continue;
69
		while (*s && isspace(*s)) s++;
70
		if (strncmp(s, "
71
		{
72
			s += 6;
73
			if (strncmp(s, ":bmp>", 5) == 0) {s += 5; v = 0;}
74
			else if (strncmp(s, ":set>", 5) == 0) {s += 5; v = 1;}
75
			else if (strncmp(s, ":life>", 6) == 0) {s += 6; v = 2;}
76
			else continue;
77
			if (!isspace(*s)) continue;
78
			while (*s && isspace(*s)) s++;
79
			if (!*s) continue;
80
			del_last_space(s);
81
			strcpy(name, s);
82
			out_end(k);
83
			type = v;
84
			continue;
85
		}
86
		else if (strncmp(s, "", 6) == 0)
87
		{
88
			s += 6;
89
			if (!isspace(*s)) continue;
90
			while (*s && isspace(*s)) s++;
91
			if (!*s) continue;
92
			i = 2*atoi(s);
93
			while (--i >= 0) out_uc(0, k);
94
			continue;
95
		}
96
		else if (strncmp(s, "
97
		{
98
			s += 7; v = 0;
99
			for (;;)
100
			{
101
				if (strncmp(s, ":inv", 4) == 0) {s += 4; v ^= 1;}
102
				else break;
103
			}
104
			if (s[0] == '>') s++;
105
			else continue;
106
		}
107
		else continue;
108
		if (!isspace(*s)) continue;
109
		while (*s && isspace(*s)) s++;
110
		if (!*s) continue;
111
		del_last_space(s);
112
		if ((PictureFileOpen(mx, my, tex, s) & PFO_MASK_ERROR) != 0) continue;
113
		if (!tex || mx <= 0 || my <= 0) continue;
114
		if (type == 0 || type == 1)
115
		{
116
			if (mx >= 256 || my >= 256) continue;
117
		}
118
		else if (type == 2)
119
		{
120
			if (mx >= 65536 || my >= 65536) continue;
121
		}
122
		slen = GetStringPictLenght(mx);
123
		if (k == -10)
124
		{
125
			printf("\nconst unsigned char %s[] = \"", name);
126
			if (type == 2) printf("#LifeBin 2.0\\n");
127
			printf("\"");
128
			k = -1;
129
		}
130
		if (v & 1)
131
		{
132
			for (i = 0; i < my; i++)
133
			{
134
				t0 = tex + slen * i;
135
				for (j = 3*mx; j > 0; j--)
136
				{
137
					t0[0] = (unsigned char)~t0[0];
138
					t0++;
139
				}
140
			}
141
		}
142
		m = 0; t = 0;
143
		if (type == 0 || type == 1)
144
		{
145
			out_uc((unsigned char)mx, k); out_uc((unsigned char)my, k);
146
		}
147
		else if (type == 2)
148
		{
149
			out_uc((unsigned char)mx, k); out_uc((unsigned char)(mx >> 8), k);
150
			out_uc((unsigned char)my, k); out_uc((unsigned char)(my >> 8), k);
151
		}
152
		for (i = 0; i < my; i++)
153
		{
154
			t0 = tex + slen * i;
155
			for (j = mx; j > 0; j--)
156
			{
157
				if (type == 0)
158
				{
159
					out_uc(t0[2], k); out_uc(t0[1], k); out_uc(t0[0], k);
160
				}
161
				else if (type == 1)
162
				{
163
					m |= ((int)t0[0] + (int)t0[1] + (int)t0[2] >= 384) << t;
164
					if (++t >= 8) {out_uc((unsigned char)m, k); m = 0; t = 0;}
165
				}
166
				else if (type == 2)
167
				{
168
					if ((int)t0[0] + (int)t0[1] + (int)t0[2] >= 384)
169
					{
170
						if (m) {out_uc((unsigned char)m, k); m = 0;}
171
						out_uc(0, k);
172
					}
173
					else
174
					{
175
						if (m == 255) {out_uc((unsigned char)m, k); m = 0;}
176
						m++;
177
					}
178
				}
179
				t0 += 3;
180
			}
181
		}
182
		if (type == 1)
183
		{
184
			if (t) out_uc((unsigned char)m, k);
185
		}
186
		else if (type == 2)
187
		{
188
			if (m) out_uc((unsigned char)m, k);
189
		}
190
	}
191
	if (tex) delete[] tex;
192
	out_end(k);
193
	printf("#endif\n");
194
	return 0;
195
}