blob: 907f9a2db7e15da815fa5273e4cdb26f9428cd2b [file] [log] [blame]
wdenkf5f146e2003-04-20 16:52:09 +00001/*
2 * (C) Copyright 2002
wdenkb9bbd242003-06-30 16:24:52 +00003 * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
wdenkf5f146e2003-04-20 16:52:09 +00004 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * BMP handling routines
26 */
27
28#include <common.h>
29#include <bmp_layout.h>
30#include <command.h>
wdenk9ca7bbc2004-10-09 23:25:58 +000031#include <asm/byteorder.h>
Stefan Roese13b93692005-10-08 10:19:07 +020032#include <malloc.h>
wdenkf5f146e2003-04-20 16:52:09 +000033
wdenkf5f146e2003-04-20 16:52:09 +000034static int bmp_info (ulong addr);
wdenke55402c2004-03-14 16:51:43 +000035static int bmp_display (ulong addr, int x, int y);
wdenkf5f146e2003-04-20 16:52:09 +000036
Stefan Roese13b93692005-10-08 10:19:07 +020037int gunzip(void *, int, unsigned char *, unsigned long *);
38
wdenkf5f146e2003-04-20 16:52:09 +000039/*
40 * Subroutine: do_bmp
41 *
42 * Description: Handler for 'bmp' command..
43 *
44 * Inputs: argv[1] contains the subcommand
45 *
46 * Return: None
47 *
48 */
49int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
50{
51 ulong addr;
wdenke55402c2004-03-14 16:51:43 +000052 int x = 0, y = 0;
wdenkf5f146e2003-04-20 16:52:09 +000053
54 switch (argc) {
55 case 2: /* use load_addr as default address */
56 addr = load_addr;
57 break;
58 case 3: /* use argument */
59 addr = simple_strtoul(argv[2], NULL, 16);
60 break;
wdenke55402c2004-03-14 16:51:43 +000061 case 5:
62 addr = simple_strtoul(argv[2], NULL, 16);
63 x = simple_strtoul(argv[3], NULL, 10);
64 y = simple_strtoul(argv[4], NULL, 10);
65 break;
wdenkf5f146e2003-04-20 16:52:09 +000066 default:
67 printf ("Usage:\n%s\n", cmdtp->usage);
68 return 1;
69 }
70
71 /* Allow for short names
72 * Adjust length if more sub-commands get added
73 */
74 if (strncmp(argv[1],"info",1) == 0) {
75 return (bmp_info(addr));
76 } else if (strncmp(argv[1],"display",1) == 0) {
wdenke55402c2004-03-14 16:51:43 +000077 return (bmp_display(addr, x, y));
wdenkf5f146e2003-04-20 16:52:09 +000078 } else {
79 printf ("Usage:\n%s\n", cmdtp->usage);
80 return 1;
81 }
82}
83
wdenkf287a242003-07-01 21:06:45 +000084U_BOOT_CMD(
wdenke55402c2004-03-14 16:51:43 +000085 bmp, 5, 1, do_bmp,
wdenkf12e3962003-06-29 21:03:46 +000086 "bmp - manipulate BMP image data\n",
wdenke55402c2004-03-14 16:51:43 +000087 "info <imageAddr> - display image info\n"
88 "bmp display <imageAddr> [x y] - display image at x,y\n"
wdenkf12e3962003-06-29 21:03:46 +000089);
90
wdenkf5f146e2003-04-20 16:52:09 +000091/*
92 * Subroutine: bmp_info
93 *
94 * Description: Show information about bmp file in memory
95 *
96 * Inputs: addr address of the bmp file
97 *
98 * Return: None
99 *
100 */
101static int bmp_info(ulong addr)
102{
103 bmp_image_t *bmp=(bmp_image_t *)addr;
Stefan Roese13b93692005-10-08 10:19:07 +0200104#ifdef CONFIG_VIDEO_BMP_GZIP
105 unsigned char *dst = NULL;
106 ulong len;
107#endif /* CONFIG_VIDEO_BMP_GZIP */
108
wdenkf5f146e2003-04-20 16:52:09 +0000109 if (!((bmp->header.signature[0]=='B') &&
110 (bmp->header.signature[1]=='M'))) {
Stefan Roese13b93692005-10-08 10:19:07 +0200111
112#ifdef CONFIG_VIDEO_BMP_GZIP
113 /*
114 * Decompress bmp image
115 */
116 len = CFG_VIDEO_LOGO_MAX_SIZE;
117 dst = malloc(CFG_VIDEO_LOGO_MAX_SIZE);
118 if (dst == NULL) {
119 printf("Error: malloc in gunzip failed!\n");
120 return(1);
121 }
122 if (gunzip(dst, CFG_VIDEO_LOGO_MAX_SIZE, (uchar *)addr, &len) != 0) {
123 printf("There is no valid bmp file at the given address\n");
124 return(1);
125 }
126 if (len == CFG_VIDEO_LOGO_MAX_SIZE) {
127 printf("Image could be truncated (increase CFG_VIDEO_LOGO_MAX_SIZE)!\n");
128 }
129
130 /*
131 * Set addr to decompressed image
132 */
133 bmp = (bmp_image_t *)dst;
134
135 /*
136 * Check for bmp mark 'BM'
137 */
138 if (!((bmp->header.signature[0] == 'B') &&
139 (bmp->header.signature[1] == 'M'))) {
140 printf("There is no valid bmp file at the given address\n");
141 free(dst);
142 return(1);
143 }
144
145 printf("Gzipped BMP image detected!\n");
146#else /* CONFIG_VIDEO_BMP_GZIP */
wdenkf5f146e2003-04-20 16:52:09 +0000147 printf("There is no valid bmp file at the given address\n");
148 return(1);
Stefan Roese13b93692005-10-08 10:19:07 +0200149#endif /* CONFIG_VIDEO_BMP_GZIP */
wdenkf5f146e2003-04-20 16:52:09 +0000150 }
151 printf("Image size : %d x %d\n", le32_to_cpu(bmp->header.width),
152 le32_to_cpu(bmp->header.height));
153 printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
154 printf("Compression : %d\n", le32_to_cpu(bmp->header.compression));
Stefan Roese13b93692005-10-08 10:19:07 +0200155
156#ifdef CONFIG_VIDEO_BMP_GZIP
157 if (dst) {
158 free(dst);
159 }
160#endif /* CONFIG_VIDEO_BMP_GZIP */
161
wdenkf5f146e2003-04-20 16:52:09 +0000162 return(0);
163}
164
165/*
166 * Subroutine: bmp_display
167 *
168 * Description: Display bmp file located in memory
169 *
170 * Inputs: addr address of the bmp file
171 *
172 * Return: None
173 *
174 */
wdenke55402c2004-03-14 16:51:43 +0000175static int bmp_display(ulong addr, int x, int y)
wdenkf5f146e2003-04-20 16:52:09 +0000176{
wdenk7ac16102004-08-01 22:48:16 +0000177#if defined(CONFIG_LCD)
178 extern int lcd_display_bitmap (ulong, int, int);
wdenkf5f146e2003-04-20 16:52:09 +0000179
wdenke55402c2004-03-14 16:51:43 +0000180 return (lcd_display_bitmap (addr, x, y));
wdenk7ac16102004-08-01 22:48:16 +0000181#elif defined(CONFIG_VIDEO)
wdenke55402c2004-03-14 16:51:43 +0000182 extern int video_display_bitmap (ulong, int, int);
183 return (video_display_bitmap (addr, x, y));
wdenk7ac16102004-08-01 22:48:16 +0000184#else
185# error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
wdenke55402c2004-03-14 16:51:43 +0000186#endif
wdenkf5f146e2003-04-20 16:52:09 +0000187}