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