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#include <common.h>
29#include <bmp_layout.h>
30#include <command.h>
31#include <asm/byteorder.h>
32#include <malloc.h>
33
34static int bmp_info (ulong addr);
35static int bmp_display (ulong addr, int x, int y);
36
37int gunzip(void *, int, unsigned char *, unsigned long *);
38
39
40
41
42
43
44
45
46
47
48#ifdef CONFIG_VIDEO_BMP_GZIP
49static bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp)
50{
51 void *dst;
52 unsigned long len;
53 bmp_image_t *bmp;
54
55
56
57
58 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
59 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
60 if (dst == NULL) {
61 puts("Error: malloc in gunzip failed!\n");
62 return NULL;
63 }
64 if (gunzip(dst, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, (uchar *)addr, &len) != 0) {
65 free(dst);
66 return NULL;
67 }
68 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)
69 puts("Image could be truncated"
70 " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
71
72 bmp = dst;
73
74
75
76
77 if (!((bmp->header.signature[0] == 'B') &&
78 (bmp->header.signature[1] == 'M'))) {
79 free(dst);
80 return NULL;
81 }
82
83 puts("Gzipped BMP image detected!\n");
84
85 return bmp;
86}
87#else
88static bmp_image_t *gunzip_bmp(unsigned long addr, unsigned long *lenp)
89{
90 return NULL;
91}
92#endif
93
94
95
96
97
98
99
100
101
102
103
104
105int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
106{
107 ulong addr;
108 int x = 0, y = 0;
109
110 switch (argc) {
111 case 2:
112 addr = load_addr;
113 break;
114 case 3:
115 addr = simple_strtoul(argv[2], NULL, 16);
116 break;
117 case 5:
118 addr = simple_strtoul(argv[2], NULL, 16);
119 x = simple_strtoul(argv[3], NULL, 10);
120 y = simple_strtoul(argv[4], NULL, 10);
121 break;
122 default:
123 cmd_usage(cmdtp);
124 return 1;
125 }
126
127
128
129
130 if (strncmp(argv[1],"info",1) == 0) {
131 return (bmp_info(addr));
132 } else if (strncmp(argv[1],"display",1) == 0) {
133 return (bmp_display(addr, x, y));
134 } else {
135 cmd_usage(cmdtp);
136 return 1;
137 }
138}
139
140U_BOOT_CMD(
141 bmp, 5, 1, do_bmp,
142 "manipulate BMP image data",
143 "info <imageAddr> - display image info\n"
144 "bmp display <imageAddr> [x y] - display image at x,y\n"
145);
146
147
148
149
150
151
152
153
154
155
156
157static int bmp_info(ulong addr)
158{
159 bmp_image_t *bmp=(bmp_image_t *)addr;
160 unsigned long len;
161
162 if (!((bmp->header.signature[0]=='B') &&
163 (bmp->header.signature[1]=='M')))
164 bmp = gunzip_bmp(addr, &len);
165
166 if (bmp == NULL) {
167 printf("There is no valid bmp file at the given address\n");
168 return 1;
169 }
170
171 printf("Image size : %d x %d\n", le32_to_cpu(bmp->header.width),
172 le32_to_cpu(bmp->header.height));
173 printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
174 printf("Compression : %d\n", le32_to_cpu(bmp->header.compression));
175
176 if ((unsigned long)bmp != addr)
177 free(bmp);
178
179 return(0);
180}
181
182
183
184
185
186
187
188
189
190
191
192static int bmp_display(ulong addr, int x, int y)
193{
194 int ret;
195 bmp_image_t *bmp = (bmp_image_t *)addr;
196 unsigned long len;
197
198 if (!((bmp->header.signature[0]=='B') &&
199 (bmp->header.signature[1]=='M')))
200 bmp = gunzip_bmp(addr, &len);
201
202 if (!bmp) {
203 printf("There is no valid bmp file at the given address\n");
204 return 1;
205 }
206
207#if defined(CONFIG_LCD)
208 extern int lcd_display_bitmap (ulong, int, int);
209
210 ret = lcd_display_bitmap ((unsigned long)bmp, x, y);
211#elif defined(CONFIG_VIDEO)
212 extern int video_display_bitmap (ulong, int, int);
213
214 ret = video_display_bitmap ((unsigned long)bmp, x, y);
215#else
216# error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
217#endif
218
219 if ((unsigned long)bmp != addr)
220 free(bmp);
221
222 return ret;
223}
224