3 * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * BMP handling routines
29 #include <bmp_layout.h>
31 #include <asm/byteorder.h>
34 static int bmp_info (ulong addr
);
35 static int bmp_display (ulong addr
, int x
, int y
);
37 int gunzip(void *, int, unsigned char *, unsigned long *);
40 * Allocate and decompress a BMP image using gunzip().
42 * Returns a pointer to the decompressed image data. Must be freed by
43 * the caller after use.
45 * Returns NULL if decompression failed, or if the decompressed data
46 * didn't contain a valid BMP signature.
48 #ifdef CONFIG_VIDEO_BMP_GZIP
49 static bmp_image_t
*gunzip_bmp(unsigned long addr
, unsigned long *lenp
)
56 * Decompress bmp image
58 len
= CFG_VIDEO_LOGO_MAX_SIZE
;
59 dst
= malloc(CFG_VIDEO_LOGO_MAX_SIZE
);
61 puts("Error: malloc in gunzip failed!\n");
64 if (gunzip(dst
, CFG_VIDEO_LOGO_MAX_SIZE
, (uchar
*)addr
, &len
) != 0) {
68 if (len
== CFG_VIDEO_LOGO_MAX_SIZE
)
69 puts("Image could be truncated"
70 " (increase CFG_VIDEO_LOGO_MAX_SIZE)!\n");
75 * Check for bmp mark 'BM'
77 if (!((bmp
->header
.signature
[0] == 'B') &&
78 (bmp
->header
.signature
[1] == 'M'))) {
83 puts("Gzipped BMP image detected!\n");
88 static bmp_image_t
*gunzip_bmp(unsigned long addr
, unsigned long *lenp
)
98 * Description: Handler for 'bmp' command..
100 * Inputs: argv[1] contains the subcommand
105 int do_bmp(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
111 case 2: /* use load_addr as default address */
114 case 3: /* use argument */
115 addr
= simple_strtoul(argv
[2], NULL
, 16);
118 addr
= simple_strtoul(argv
[2], NULL
, 16);
119 x
= simple_strtoul(argv
[3], NULL
, 10);
120 y
= simple_strtoul(argv
[4], NULL
, 10);
123 printf ("Usage:\n%s\n", cmdtp
->usage
);
127 /* Allow for short names
128 * Adjust length if more sub-commands get added
130 if (strncmp(argv
[1],"info",1) == 0) {
131 return (bmp_info(addr
));
132 } else if (strncmp(argv
[1],"display",1) == 0) {
133 return (bmp_display(addr
, x
, y
));
135 printf ("Usage:\n%s\n", cmdtp
->usage
);
142 "bmp - manipulate BMP image data\n",
143 "info <imageAddr> - display image info\n"
144 "bmp display <imageAddr> [x y] - display image at x,y\n"
148 * Subroutine: bmp_info
150 * Description: Show information about bmp file in memory
152 * Inputs: addr address of the bmp file
157 static int bmp_info(ulong addr
)
159 bmp_image_t
*bmp
=(bmp_image_t
*)addr
;
162 if (!((bmp
->header
.signature
[0]=='B') &&
163 (bmp
->header
.signature
[1]=='M')))
164 bmp
= gunzip_bmp(addr
, &len
);
167 printf("There is no valid bmp file at the given address\n");
171 printf("Image size : %d x %d\n", le32_to_cpu(bmp
->header
.width
),
172 le32_to_cpu(bmp
->header
.height
));
173 printf("Bits per pixel: %d\n", le16_to_cpu(bmp
->header
.bit_count
));
174 printf("Compression : %d\n", le32_to_cpu(bmp
->header
.compression
));
176 if ((unsigned long)bmp
!= addr
)
183 * Subroutine: bmp_display
185 * Description: Display bmp file located in memory
187 * Inputs: addr address of the bmp file
192 static int bmp_display(ulong addr
, int x
, int y
)
195 bmp_image_t
*bmp
= (bmp_image_t
*)addr
;
198 if (!((bmp
->header
.signature
[0]=='B') &&
199 (bmp
->header
.signature
[1]=='M')))
200 bmp
= gunzip_bmp(addr
, &len
);
203 printf("There is no valid bmp file at the given address\n");
207 #if defined(CONFIG_LCD)
208 extern int lcd_display_bitmap (ulong
, int, int);
210 ret
= lcd_display_bitmap ((unsigned long)bmp
, x
, y
);
211 #elif defined(CONFIG_VIDEO)
212 extern int video_display_bitmap (ulong
, int, int);
214 ret
= video_display_bitmap ((unsigned long)bmp
, x
, y
);
216 # error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
219 if ((unsigned long)bmp
!= addr
)