3 * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 * BMP handling routines
14 #include <bmp_layout.h>
16 #include <asm/byteorder.h>
22 static int bmp_info (ulong addr);
25 * Allocate and decompress a BMP image using gunzip().
27 * Returns a pointer to the decompressed image data. This pointer is
28 * aligned to 32-bit-aligned-address + 2.
29 * See doc/README.displaying-bmps for explanation.
31 * The allocation address is passed to 'alloc_addr' and must be freed
32 * by the caller after use.
34 * Returns NULL if decompression failed, or if the decompressed data
35 * didn't contain a valid BMP signature.
37 #ifdef CONFIG_VIDEO_BMP_GZIP
38 struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
43 struct bmp_image *bmp;
46 * Decompress bmp image
48 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
49 /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */
50 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE + 3);
52 puts("Error: malloc in gunzip failed!\n");
58 /* align to 32-bit-aligned-address + 2 */
59 bmp = (struct bmp_image *)((((unsigned int)dst + 1) & ~3) + 2);
61 if (gunzip(bmp, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, map_sysmem(addr, 0),
66 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)
67 puts("Image could be truncated"
68 " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
71 * Check for bmp mark 'BM'
73 if (!((bmp->header.signature[0] == 'B') &&
74 (bmp->header.signature[1] == 'M'))) {
79 debug("Gzipped BMP image detected!\n");
85 struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
92 static int do_bmp_info(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
97 case 1: /* use load_addr as default address */
100 case 2: /* use argument */
101 addr = simple_strtoul(argv[1], NULL, 16);
104 return CMD_RET_USAGE;
107 return (bmp_info(addr));
110 static int do_bmp_display(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
115 splash_get_pos(&x, &y);
118 case 1: /* use load_addr as default address */
121 case 2: /* use argument */
122 addr = simple_strtoul(argv[1], NULL, 16);
125 addr = simple_strtoul(argv[1], NULL, 16);
126 x = simple_strtoul(argv[2], NULL, 10);
127 y = simple_strtoul(argv[3], NULL, 10);
130 return CMD_RET_USAGE;
133 return (bmp_display(addr, x, y));
136 static cmd_tbl_t cmd_bmp_sub[] = {
137 U_BOOT_CMD_MKENT(info, 3, 0, do_bmp_info, "", ""),
138 U_BOOT_CMD_MKENT(display, 5, 0, do_bmp_display, "", ""),
141 #ifdef CONFIG_NEEDS_MANUAL_RELOC
142 void bmp_reloc(void) {
143 fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub));
150 * Description: Handler for 'bmp' command..
152 * Inputs: argv[1] contains the subcommand
157 static int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
161 /* Strip off leading 'bmp' command argument */
165 c = find_cmd_tbl(argv[0], &cmd_bmp_sub[0], ARRAY_SIZE(cmd_bmp_sub));
168 return c->cmd(cmdtp, flag, argc, argv);
170 return CMD_RET_USAGE;
175 "manipulate BMP image data",
176 "info <imageAddr> - display image info\n"
177 "bmp display <imageAddr> [x y] - display image at x,y"
181 * Subroutine: bmp_info
183 * Description: Show information about bmp file in memory
185 * Inputs: addr address of the bmp file
190 static int bmp_info(ulong addr)
192 struct bmp_image *bmp = (struct bmp_image *)map_sysmem(addr, 0);
193 void *bmp_alloc_addr = NULL;
196 if (!((bmp->header.signature[0]=='B') &&
197 (bmp->header.signature[1]=='M')))
198 bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
201 printf("There is no valid bmp file at the given address\n");
205 printf("Image size : %d x %d\n", le32_to_cpu(bmp->header.width),
206 le32_to_cpu(bmp->header.height));
207 printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
208 printf("Compression : %d\n", le32_to_cpu(bmp->header.compression));
211 free(bmp_alloc_addr);
217 * Subroutine: bmp_display
219 * Description: Display bmp file located in memory
221 * Inputs: addr address of the bmp file
226 int bmp_display(ulong addr, int x, int y)
229 struct bmp_image *bmp = map_sysmem(addr, 0);
230 void *bmp_alloc_addr = NULL;
233 if (!((bmp->header.signature[0]=='B') &&
234 (bmp->header.signature[1]=='M')))
235 bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
238 printf("There is no valid bmp file at the given address\n");
241 addr = map_to_sysmem(bmp);
243 #if defined(CONFIG_LCD)
244 ret = lcd_display_bitmap(addr, x, y);
245 #elif defined(CONFIG_VIDEO)
246 ret = video_display_bitmap(addr, x, y);
248 # error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
252 free(bmp_alloc_addr);