Blame view
cmd/bmp.c
5.75 KB
059ae173e Add files needed ... |
1 2 |
/* * (C) Copyright 2002 |
b37c7e5e5 * Patch by Seb Ja... |
3 |
* Detlev Zundel, DENX Software Engineering, dzu@denx.de. |
059ae173e Add files needed ... |
4 |
* |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
059ae173e Add files needed ... |
6 7 8 9 10 11 12 |
*/ /* * BMP handling routines */ #include <common.h> |
b01c7923e dm: video: Implem... |
13 |
#include <dm.h> |
6111722a9 video: move exter... |
14 |
#include <lcd.h> |
b01c7923e dm: video: Implem... |
15 |
#include <mapmem.h> |
059ae173e Add files needed ... |
16 17 |
#include <bmp_layout.h> #include <command.h> |
8655b6f86 * Clean up tools/... |
18 |
#include <asm/byteorder.h> |
c29ab9d71 Fix gzip bmp supp... |
19 |
#include <malloc.h> |
72b335e91 sandbox: Support ... |
20 |
#include <mapmem.h> |
ff8fb56b6 video: consolidat... |
21 |
#include <splash.h> |
f674f7cfc video: Provide an... |
22 |
#include <video.h> |
059ae173e Add files needed ... |
23 |
|
059ae173e Add files needed ... |
24 |
static int bmp_info (ulong addr); |
059ae173e Add files needed ... |
25 26 |
/* |
43ef1c381 cmd_bmp: Add supp... |
27 28 |
* Allocate and decompress a BMP image using gunzip(). * |
f7ef9d610 lcd: align bmp he... |
29 30 31 32 33 34 |
* Returns a pointer to the decompressed image data. This pointer is * aligned to 32-bit-aligned-address + 2. * See doc/README.displaying-bmps for explanation. * * The allocation address is passed to 'alloc_addr' and must be freed * by the caller after use. |
43ef1c381 cmd_bmp: Add supp... |
35 36 37 38 39 |
* * Returns NULL if decompression failed, or if the decompressed data * didn't contain a valid BMP signature. */ #ifdef CONFIG_VIDEO_BMP_GZIP |
1c3dbe56f Remove typedefs f... |
40 41 |
struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp, void **alloc_addr) |
43ef1c381 cmd_bmp: Add supp... |
42 43 44 |
{ void *dst; unsigned long len; |
1c3dbe56f Remove typedefs f... |
45 |
struct bmp_image *bmp; |
43ef1c381 cmd_bmp: Add supp... |
46 47 48 49 |
/* * Decompress bmp image */ |
6d0f6bcf3 rename CFG_ macro... |
50 |
len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE; |
f7ef9d610 lcd: align bmp he... |
51 52 |
/* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */ dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE + 3); |
43ef1c381 cmd_bmp: Add supp... |
53 54 55 56 57 |
if (dst == NULL) { puts("Error: malloc in gunzip failed! "); return NULL; } |
f7ef9d610 lcd: align bmp he... |
58 59 60 61 |
bmp = dst; /* align to 32-bit-aligned-address + 2 */ |
1c3dbe56f Remove typedefs f... |
62 |
bmp = (struct bmp_image *)((((unsigned int)dst + 1) & ~3) + 2); |
f7ef9d610 lcd: align bmp he... |
63 |
|
72b335e91 sandbox: Support ... |
64 65 |
if (gunzip(bmp, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, map_sysmem(addr, 0), &len) != 0) { |
43ef1c381 cmd_bmp: Add supp... |
66 67 68 |
free(dst); return NULL; } |
6d0f6bcf3 rename CFG_ macro... |
69 |
if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) |
43ef1c381 cmd_bmp: Add supp... |
70 |
puts("Image could be truncated" |
6d0f6bcf3 rename CFG_ macro... |
71 72 |
" (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)! "); |
43ef1c381 cmd_bmp: Add supp... |
73 |
|
43ef1c381 cmd_bmp: Add supp... |
74 75 76 77 78 79 80 81 |
/* * Check for bmp mark 'BM' */ if (!((bmp->header.signature[0] == 'B') && (bmp->header.signature[1] == 'M'))) { free(dst); return NULL; } |
17f79e45e cmd_bmp.c: messag... |
82 83 |
debug("Gzipped BMP image detected! "); |
43ef1c381 cmd_bmp: Add supp... |
84 |
|
f7ef9d610 lcd: align bmp he... |
85 |
*alloc_addr = dst; |
43ef1c381 cmd_bmp: Add supp... |
86 87 88 |
return bmp; } #else |
1c3dbe56f Remove typedefs f... |
89 90 |
struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp, void **alloc_addr) |
43ef1c381 cmd_bmp: Add supp... |
91 92 93 94 |
{ return NULL; } #endif |
54841ab50 Make sure that ar... |
95 |
static int do_bmp_info(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
9acd4f0e9 cmd_bmp.c: add st... |
96 97 |
{ ulong addr; |
43ef1c381 cmd_bmp: Add supp... |
98 |
|
9acd4f0e9 cmd_bmp.c: add st... |
99 100 101 102 103 104 105 106 |
switch (argc) { case 1: /* use load_addr as default address */ addr = load_addr; break; case 2: /* use argument */ addr = simple_strtoul(argv[1], NULL, 16); break; default: |
4c12eeb8b Convert cmd_usage... |
107 |
return CMD_RET_USAGE; |
9acd4f0e9 cmd_bmp.c: add st... |
108 109 110 111 |
} return (bmp_info(addr)); } |
54841ab50 Make sure that ar... |
112 |
static int do_bmp_display(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
059ae173e Add files needed ... |
113 114 |
{ ulong addr; |
4b248f3f7 * Patch by Pierr... |
115 |
int x = 0, y = 0; |
059ae173e Add files needed ... |
116 |
|
ff8fb56b6 video: consolidat... |
117 |
splash_get_pos(&x, &y); |
059ae173e Add files needed ... |
118 |
switch (argc) { |
9acd4f0e9 cmd_bmp.c: add st... |
119 |
case 1: /* use load_addr as default address */ |
059ae173e Add files needed ... |
120 121 |
addr = load_addr; break; |
9acd4f0e9 cmd_bmp.c: add st... |
122 123 |
case 2: /* use argument */ addr = simple_strtoul(argv[1], NULL, 16); |
059ae173e Add files needed ... |
124 |
break; |
9acd4f0e9 cmd_bmp.c: add st... |
125 126 |
case 4: addr = simple_strtoul(argv[1], NULL, 16); |
93e145964 Coding Style clea... |
127 128 129 |
x = simple_strtoul(argv[2], NULL, 10); y = simple_strtoul(argv[3], NULL, 10); break; |
059ae173e Add files needed ... |
130 |
default: |
4c12eeb8b Convert cmd_usage... |
131 |
return CMD_RET_USAGE; |
059ae173e Add files needed ... |
132 |
} |
9acd4f0e9 cmd_bmp.c: add st... |
133 134 135 136 137 138 139 |
return (bmp_display(addr, x, y)); } static cmd_tbl_t cmd_bmp_sub[] = { U_BOOT_CMD_MKENT(info, 3, 0, do_bmp_info, "", ""), U_BOOT_CMD_MKENT(display, 5, 0, do_bmp_display, "", ""), }; |
2e5167cca Replace CONFIG_RE... |
140 |
#ifdef CONFIG_NEEDS_MANUAL_RELOC |
f1d2b313c ARM: add relocati... |
141 142 143 144 |
void bmp_reloc(void) { fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub)); } #endif |
9acd4f0e9 cmd_bmp.c: add st... |
145 146 147 148 149 150 151 152 153 154 |
/* * Subroutine: do_bmp * * Description: Handler for 'bmp' command.. * * Inputs: argv[1] contains the subcommand * * Return: None * */ |
54841ab50 Make sure that ar... |
155 |
static int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
9acd4f0e9 cmd_bmp.c: add st... |
156 157 158 159 160 161 162 163 |
{ cmd_tbl_t *c; /* Strip off leading 'bmp' command argument */ argc--; argv++; c = find_cmd_tbl(argv[0], &cmd_bmp_sub[0], ARRAY_SIZE(cmd_bmp_sub)); |
47e26b1bf cmd_usage(): simp... |
164 |
if (c) |
9acd4f0e9 cmd_bmp.c: add st... |
165 |
return c->cmd(cmdtp, flag, argc, argv); |
47e26b1bf cmd_usage(): simp... |
166 |
else |
4c12eeb8b Convert cmd_usage... |
167 |
return CMD_RET_USAGE; |
059ae173e Add files needed ... |
168 |
} |
0d4983930 Patch by Kenneth ... |
169 |
U_BOOT_CMD( |
4b248f3f7 * Patch by Pierr... |
170 |
bmp, 5, 1, do_bmp, |
2fb2604d5 Command usage cle... |
171 |
"manipulate BMP image data", |
4b248f3f7 * Patch by Pierr... |
172 173 |
"info <imageAddr> - display image info " |
a89c33db9 General help mess... |
174 |
"bmp display <imageAddr> [x y] - display image at x,y" |
b0fce99bf Fix some missing ... |
175 |
); |
059ae173e Add files needed ... |
176 177 178 179 180 181 182 183 184 185 186 187 |
/* * Subroutine: bmp_info * * Description: Show information about bmp file in memory * * Inputs: addr address of the bmp file * * Return: None * */ static int bmp_info(ulong addr) { |
72b335e91 sandbox: Support ... |
188 |
struct bmp_image *bmp = (struct bmp_image *)map_sysmem(addr, 0); |
f7ef9d610 lcd: align bmp he... |
189 |
void *bmp_alloc_addr = NULL; |
43ef1c381 cmd_bmp: Add supp... |
190 |
unsigned long len; |
c29ab9d71 Fix gzip bmp supp... |
191 |
|
059ae173e Add files needed ... |
192 |
if (!((bmp->header.signature[0]=='B') && |
43ef1c381 cmd_bmp: Add supp... |
193 |
(bmp->header.signature[1]=='M'))) |
f7ef9d610 lcd: align bmp he... |
194 |
bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr); |
c29ab9d71 Fix gzip bmp supp... |
195 |
|
43ef1c381 cmd_bmp: Add supp... |
196 |
if (bmp == NULL) { |
059ae173e Add files needed ... |
197 198 |
printf("There is no valid bmp file at the given address "); |
43ef1c381 cmd_bmp: Add supp... |
199 |
return 1; |
059ae173e Add files needed ... |
200 |
} |
43ef1c381 cmd_bmp: Add supp... |
201 |
|
059ae173e Add files needed ... |
202 203 204 205 206 207 208 |
printf("Image size : %d x %d ", le32_to_cpu(bmp->header.width), le32_to_cpu(bmp->header.height)); printf("Bits per pixel: %d ", le16_to_cpu(bmp->header.bit_count)); printf("Compression : %d ", le32_to_cpu(bmp->header.compression)); |
c29ab9d71 Fix gzip bmp supp... |
209 |
|
f7ef9d610 lcd: align bmp he... |
210 211 |
if (bmp_alloc_addr) free(bmp_alloc_addr); |
c29ab9d71 Fix gzip bmp supp... |
212 |
|
059ae173e Add files needed ... |
213 214 215 216 217 218 219 220 221 222 223 224 225 |
return(0); } /* * Subroutine: bmp_display * * Description: Display bmp file located in memory * * Inputs: addr address of the bmp file * * Return: None * */ |
de3b49c4d cmd_bmp.c: make b... |
226 |
int bmp_display(ulong addr, int x, int y) |
059ae173e Add files needed ... |
227 |
{ |
b01c7923e dm: video: Implem... |
228 229 230 |
#ifdef CONFIG_DM_VIDEO struct udevice *dev; #endif |
43ef1c381 cmd_bmp: Add supp... |
231 |
int ret; |
72b335e91 sandbox: Support ... |
232 |
struct bmp_image *bmp = map_sysmem(addr, 0); |
f7ef9d610 lcd: align bmp he... |
233 |
void *bmp_alloc_addr = NULL; |
43ef1c381 cmd_bmp: Add supp... |
234 235 236 237 |
unsigned long len; if (!((bmp->header.signature[0]=='B') && (bmp->header.signature[1]=='M'))) |
f7ef9d610 lcd: align bmp he... |
238 |
bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr); |
43ef1c381 cmd_bmp: Add supp... |
239 240 241 242 243 244 |
if (!bmp) { printf("There is no valid bmp file at the given address "); return 1; } |
72b335e91 sandbox: Support ... |
245 |
addr = map_to_sysmem(bmp); |
43ef1c381 cmd_bmp: Add supp... |
246 |
|
b01c7923e dm: video: Implem... |
247 |
#ifdef CONFIG_DM_VIDEO |
3f603cbbb dm: Use uclass_fi... |
248 |
ret = uclass_first_device_err(UCLASS_VIDEO, &dev); |
b01c7923e dm: video: Implem... |
249 |
if (!ret) { |
3f603cbbb dm: Use uclass_fi... |
250 |
bool align = false; |
b01c7923e dm: video: Implem... |
251 252 |
# ifdef CONFIG_SPLASH_SCREEN_ALIGN |
3f603cbbb dm: Use uclass_fi... |
253 |
align = true; |
b01c7923e dm: video: Implem... |
254 |
# endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
3f603cbbb dm: Use uclass_fi... |
255 |
ret = video_bmp_display(dev, addr, x, y, align); |
b01c7923e dm: video: Implem... |
256 |
} |
b01c7923e dm: video: Implem... |
257 |
#elif defined(CONFIG_LCD) |
72b335e91 sandbox: Support ... |
258 |
ret = lcd_display_bitmap(addr, x, y); |
281e00a3b * Code cleanup |
259 |
#elif defined(CONFIG_VIDEO) |
72b335e91 sandbox: Support ... |
260 |
ret = video_display_bitmap(addr, x, y); |
281e00a3b * Code cleanup |
261 262 |
#else # error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO |
4b248f3f7 * Patch by Pierr... |
263 |
#endif |
43ef1c381 cmd_bmp: Add supp... |
264 |
|
f7ef9d610 lcd: align bmp he... |
265 266 |
if (bmp_alloc_addr) free(bmp_alloc_addr); |
43ef1c381 cmd_bmp: Add supp... |
267 |
|
e517db73a cmd: Fix control ... |
268 |
return ret ? CMD_RET_FAILURE : 0; |
059ae173e Add files needed ... |
269 |
} |