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>
21 static int bmp_info (ulong addr
);
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.
36 #ifdef CONFIG_VIDEO_BMP_GZIP
37 bmp_image_t
*gunzip_bmp(unsigned long addr
, unsigned long *lenp
,
45 * Decompress bmp image
47 len
= CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
;
48 /* allocate extra 3 bytes for 32-bit-aligned-address + 2 alignment */
49 dst
= malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
+ 3);
51 puts("Error: malloc in gunzip failed!\n");
57 /* align to 32-bit-aligned-address + 2 */
58 bmp
= (bmp_image_t
*)((((unsigned int)dst
+ 1) & ~3) + 2);
60 if (gunzip(bmp
, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
, (uchar
*)addr
, &len
) != 0) {
64 if (len
== CONFIG_SYS_VIDEO_LOGO_MAX_SIZE
)
65 puts("Image could be truncated"
66 " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
69 * Check for bmp mark 'BM'
71 if (!((bmp
->header
.signature
[0] == 'B') &&
72 (bmp
->header
.signature
[1] == 'M'))) {
77 debug("Gzipped BMP image detected!\n");
83 bmp_image_t
*gunzip_bmp(unsigned long addr
, unsigned long *lenp
,
90 static int do_bmp_info(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
95 case 1: /* use load_addr as default address */
98 case 2: /* use argument */
99 addr
= simple_strtoul(argv
[1], NULL
, 16);
102 return CMD_RET_USAGE
;
105 return (bmp_info(addr
));
108 static int do_bmp_display(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[])
113 splash_get_pos(&x
, &y
);
116 case 1: /* use load_addr as default address */
119 case 2: /* use argument */
120 addr
= simple_strtoul(argv
[1], NULL
, 16);
123 addr
= simple_strtoul(argv
[1], NULL
, 16);
124 x
= simple_strtoul(argv
[2], NULL
, 10);
125 y
= simple_strtoul(argv
[3], NULL
, 10);
128 return CMD_RET_USAGE
;
131 return (bmp_display(addr
, x
, y
));
134 static cmd_tbl_t cmd_bmp_sub
[] = {
135 U_BOOT_CMD_MKENT(info
, 3, 0, do_bmp_info
, "", ""),
136 U_BOOT_CMD_MKENT(display
, 5, 0, do_bmp_display
, "", ""),
139 #ifdef CONFIG_NEEDS_MANUAL_RELOC
140 void bmp_reloc(void) {
141 fixup_cmdtable(cmd_bmp_sub
, ARRAY_SIZE(cmd_bmp_sub
));
148 * Description: Handler for 'bmp' command..
150 * Inputs: argv[1] contains the subcommand
155 static int do_bmp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
159 /* Strip off leading 'bmp' command argument */
163 c
= find_cmd_tbl(argv
[0], &cmd_bmp_sub
[0], ARRAY_SIZE(cmd_bmp_sub
));
166 return c
->cmd(cmdtp
, flag
, argc
, argv
);
168 return CMD_RET_USAGE
;
173 "manipulate BMP image data",
174 "info <imageAddr> - display image info\n"
175 "bmp display <imageAddr> [x y] - display image at x,y"
179 * Subroutine: bmp_info
181 * Description: Show information about bmp file in memory
183 * Inputs: addr address of the bmp file
188 static int bmp_info(ulong addr
)
190 bmp_image_t
*bmp
=(bmp_image_t
*)addr
;
191 void *bmp_alloc_addr
= NULL
;
194 if (!((bmp
->header
.signature
[0]=='B') &&
195 (bmp
->header
.signature
[1]=='M')))
196 bmp
= gunzip_bmp(addr
, &len
, &bmp_alloc_addr
);
199 printf("There is no valid bmp file at the given address\n");
203 printf("Image size : %d x %d\n", le32_to_cpu(bmp
->header
.width
),
204 le32_to_cpu(bmp
->header
.height
));
205 printf("Bits per pixel: %d\n", le16_to_cpu(bmp
->header
.bit_count
));
206 printf("Compression : %d\n", le32_to_cpu(bmp
->header
.compression
));
209 free(bmp_alloc_addr
);
215 * Subroutine: bmp_display
217 * Description: Display bmp file located in memory
219 * Inputs: addr address of the bmp file
224 int bmp_display(ulong addr
, int x
, int y
)
227 bmp_image_t
*bmp
= (bmp_image_t
*)addr
;
228 void *bmp_alloc_addr
= NULL
;
231 if (!((bmp
->header
.signature
[0]=='B') &&
232 (bmp
->header
.signature
[1]=='M')))
233 bmp
= gunzip_bmp(addr
, &len
, &bmp_alloc_addr
);
236 printf("There is no valid bmp file at the given address\n");
240 #if defined(CONFIG_LCD)
241 ret
= lcd_display_bitmap((ulong
)bmp
, x
, y
);
242 #elif defined(CONFIG_VIDEO)
243 ret
= video_display_bitmap((unsigned long)bmp
, x
, y
);
245 # error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
249 free(bmp_alloc_addr
);