3 * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 * BMP handling routines
16 #include <bmp_layout.h>
18 #include <asm/byteorder.h>
24 static int bmp_info (ulong addr);
27 * Allocate and decompress a BMP image using gunzip().
29 * Returns a pointer to the decompressed image data. This pointer is
30 * aligned to 32-bit-aligned-address + 2.
31 * See doc/README.displaying-bmps for explanation.
33 * The allocation address is passed to 'alloc_addr' and must be freed
34 * by the caller after use.
36 * Returns NULL if decompression failed, or if the decompressed data
37 * didn't contain a valid BMP signature.
39 #ifdef CONFIG_VIDEO_BMP_GZIP
40 struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
45 struct bmp_image *bmp;
48 * Decompress bmp image
50 len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
51 /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */
52 dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE + 3);
54 puts("Error: malloc in gunzip failed!\n");
60 /* align to 32-bit-aligned-address + 2 */
61 bmp = (struct bmp_image *)((((unsigned int)dst + 1) & ~3) + 2);
63 if (gunzip(bmp, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE, map_sysmem(addr, 0),
68 if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)
69 puts("Image could be truncated"
70 " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
73 * Check for bmp mark 'BM'
75 if (!((bmp->header.signature[0] == 'B') &&
76 (bmp->header.signature[1] == 'M'))) {
81 debug("Gzipped BMP image detected!\n");
87 struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
94 static int do_bmp_info(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
99 case 1: /* use load_addr as default address */
102 case 2: /* use argument */
103 addr = simple_strtoul(argv[1], NULL, 16);
106 return CMD_RET_USAGE;
109 return (bmp_info(addr));
112 static int do_bmp_display(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
117 splash_get_pos(&x, &y);
120 case 1: /* use load_addr as default address */
123 case 2: /* use argument */
124 addr = simple_strtoul(argv[1], NULL, 16);
127 addr = simple_strtoul(argv[1], NULL, 16);
128 x = simple_strtoul(argv[2], NULL, 10);
129 y = simple_strtoul(argv[3], NULL, 10);
132 return CMD_RET_USAGE;
135 return (bmp_display(addr, x, y));
138 static cmd_tbl_t cmd_bmp_sub[] = {
139 U_BOOT_CMD_MKENT(info, 3, 0, do_bmp_info, "", ""),
140 U_BOOT_CMD_MKENT(display, 5, 0, do_bmp_display, "", ""),
143 #ifdef CONFIG_NEEDS_MANUAL_RELOC
144 void bmp_reloc(void) {
145 fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub));
152 * Description: Handler for 'bmp' command..
154 * Inputs: argv[1] contains the subcommand
159 static int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
163 /* Strip off leading 'bmp' command argument */
167 c = find_cmd_tbl(argv[0], &cmd_bmp_sub[0], ARRAY_SIZE(cmd_bmp_sub));
170 return c->cmd(cmdtp, flag, argc, argv);
172 return CMD_RET_USAGE;
177 "manipulate BMP image data",
178 "info <imageAddr> - display image info\n"
179 "bmp display <imageAddr> [x y] - display image at x,y"
183 * Subroutine: bmp_info
185 * Description: Show information about bmp file in memory
187 * Inputs: addr address of the bmp file
192 static int bmp_info(ulong addr)
194 struct bmp_image *bmp = (struct bmp_image *)map_sysmem(addr, 0);
195 void *bmp_alloc_addr = NULL;
198 if (!((bmp->header.signature[0]=='B') &&
199 (bmp->header.signature[1]=='M')))
200 bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
203 printf("There is no valid bmp file at the given address\n");
207 printf("Image size : %d x %d\n", le32_to_cpu(bmp->header.width),
208 le32_to_cpu(bmp->header.height));
209 printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
210 printf("Compression : %d\n", le32_to_cpu(bmp->header.compression));
213 free(bmp_alloc_addr);
219 * Subroutine: bmp_display
221 * Description: Display bmp file located in memory
223 * Inputs: addr address of the bmp file
228 int bmp_display(ulong addr, int x, int y)
230 #ifdef CONFIG_DM_VIDEO
234 struct bmp_image *bmp = map_sysmem(addr, 0);
235 void *bmp_alloc_addr = NULL;
238 if (!((bmp->header.signature[0]=='B') &&
239 (bmp->header.signature[1]=='M')))
240 bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
243 printf("There is no valid bmp file at the given address\n");
246 addr = map_to_sysmem(bmp);
248 #ifdef CONFIG_DM_VIDEO
249 ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
253 # ifdef CONFIG_SPLASH_SCREEN_ALIGN
255 # endif /* CONFIG_SPLASH_SCREEN_ALIGN */
256 ret = video_bmp_display(dev, addr, x, y, align);
258 #elif defined(CONFIG_LCD)
259 ret = lcd_display_bitmap(addr, x, y);
260 #elif defined(CONFIG_VIDEO)
261 ret = video_display_bitmap(addr, x, y);
263 # error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
267 free(bmp_alloc_addr);
269 return ret ? CMD_RET_FAILURE : 0;