Subversion Repositories Kolibri OS

Rev

Rev 1769 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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