1 // SPDX-License-Identifier: GPL-2.0+
8 * BMP handling routines
12 #include <bmp_layout.h>
21 #include <asm/byteorder.h>
24 * Allocate and decompress a BMP image using gunzip().
26 * Returns a pointer to the decompressed image data. This pointer is
27 * aligned to 32-bit-aligned-address + 2.
28 * See doc/README.displaying-bmps for explanation.
30 * The allocation address is passed to 'alloc_addr' and must be freed
31 * by the caller after use.
33 * Returns NULL if decompression failed, or if the decompressed data
34 * didn't contain a valid BMP signature or decompression is not enabled in
37 struct bmp_image *gunzip_bmp(unsigned long addr, unsigned long *lenp,
42 struct bmp_image *bmp;
44 if (!CONFIG_IS_ENABLED(VIDEO_BMP_GZIP))
48 * Decompress bmp image
50 len = CONFIG_VAL(VIDEO_LOGO_MAX_SIZE);
51 /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */
52 dst = malloc(CONFIG_VAL(VIDEO_LOGO_MAX_SIZE) + 3);
54 puts("Error: malloc in gunzip failed!\n");
58 /* align to 32-bit-aligned-address + 2 */
61 if (gunzip(bmp, CONFIG_VAL(VIDEO_LOGO_MAX_SIZE), map_sysmem(addr, 0),
66 if (len == CONFIG_VAL(VIDEO_LOGO_MAX_SIZE))
67 puts("Image could be truncated (increase CONFIG_VIDEO_LOGO_MAX_SIZE)!\n");
70 * Check for bmp mark 'BM'
72 if (!((bmp->header.signature[0] == 'B') &&
73 (bmp->header.signature[1] == 'M'))) {
78 debug("Gzipped BMP image detected!\n");
84 #ifdef CONFIG_NEEDS_MANUAL_RELOC
87 fixup_cmdtable(cmd_bmp_sub, ARRAY_SIZE(cmd_bmp_sub));
91 int bmp_info(ulong addr)
93 struct bmp_image *bmp = (struct bmp_image *)map_sysmem(addr, 0);
94 void *bmp_alloc_addr = NULL;
97 if (!((bmp->header.signature[0] == 'B') &&
98 (bmp->header.signature[1] == 'M')))
99 bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
102 printf("There is no valid bmp file at the given address\n");
106 printf("Image size : %d x %d\n", le32_to_cpu(bmp->header.width),
107 le32_to_cpu(bmp->header.height));
108 printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
109 printf("Compression : %d\n", le32_to_cpu(bmp->header.compression));
112 free(bmp_alloc_addr);
117 int bmp_display(ulong addr, int x, int y)
121 struct bmp_image *bmp = map_sysmem(addr, 0);
122 void *bmp_alloc_addr = NULL;
125 if (!((bmp->header.signature[0] == 'B') &&
126 (bmp->header.signature[1] == 'M')))
127 bmp = gunzip_bmp(addr, &len, &bmp_alloc_addr);
130 printf("There is no valid bmp file at the given address\n");
133 addr = map_to_sysmem(bmp);
135 ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
139 if (x == BMP_ALIGN_CENTER || y == BMP_ALIGN_CENTER)
142 ret = video_bmp_display(dev, addr, x, y, align);
146 free(bmp_alloc_addr);
148 return ret ? CMD_RET_FAILURE : 0;