]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_bmp.c
Merge commit '87ddedd'
[karo-tx-uboot.git] / common / cmd_bmp.c
1 /*
2  * (C) Copyright 2002
3  * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
4  *
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>
31 #include <asm/byteorder.h>
32 #include <malloc.h>
33
34 static int bmp_info (ulong addr);
35 static int bmp_display (ulong addr, int x, int y);
36
37 int gunzip(void *, int, unsigned char *, unsigned long *);
38
39 /*
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  */
49 int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
50 {
51         ulong addr;
52         int x = 0, y = 0;
53
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;
61         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;
66         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) {
77             return (bmp_display(addr, x, y));
78         } else {
79                 printf ("Usage:\n%s\n", cmdtp->usage);
80                 return 1;
81         }
82 }
83
84 U_BOOT_CMD(
85         bmp,    5,      1,      do_bmp,
86         "bmp     - manipulate BMP image data\n",
87         "info <imageAddr>          - display image info\n"
88         "bmp display <imageAddr> [x y] - display image at x,y\n"
89 );
90
91 /*
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  */
101 static int bmp_info(ulong addr)
102 {
103         bmp_image_t *bmp=(bmp_image_t *)addr;
104 #ifdef CONFIG_VIDEO_BMP_GZIP
105         unsigned char *dst = NULL;
106         ulong len;
107 #endif /* CONFIG_VIDEO_BMP_GZIP */
108
109         if (!((bmp->header.signature[0]=='B') &&
110               (bmp->header.signature[1]=='M'))) {
111
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 */
147                 printf("There is no valid bmp file at the given address\n");
148                 return(1);
149 #endif /* CONFIG_VIDEO_BMP_GZIP */
150         }
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));
155
156 #ifdef CONFIG_VIDEO_BMP_GZIP
157         if (dst) {
158                 free(dst);
159         }
160 #endif /* CONFIG_VIDEO_BMP_GZIP */
161
162         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  */
175 static int bmp_display(ulong addr, int x, int y)
176 {
177 #if defined(CONFIG_LCD)
178         extern int lcd_display_bitmap (ulong, int, int);
179
180         return (lcd_display_bitmap (addr, x, y));
181 #elif defined(CONFIG_VIDEO)
182         extern int video_display_bitmap (ulong, int, int);
183         return (video_display_bitmap (addr, x, y));
184 #else
185 # error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO
186 #endif
187 }