wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
wdenk | b37c7e5 | 2003-06-30 16:24:52 +0000 | [diff] [blame] | 3 | * Detlev Zundel, DENX Software Engineering, dzu@denx.de. |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 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> |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 31 | #include <asm/byteorder.h> |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 32 | #include <malloc.h> |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 33 | |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 34 | static int bmp_info (ulong addr); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 35 | static int bmp_display (ulong addr, int x, int y); |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 36 | |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 37 | int gunzip(void *, int, unsigned char *, unsigned long *); |
| 38 | |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 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; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 52 | int x = 0, y = 0; |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 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; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 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; |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 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) { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 77 | return (bmp_display(addr, x, y)); |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 78 | } else { |
| 79 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 80 | return 1; |
| 81 | } |
| 82 | } |
| 83 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 84 | U_BOOT_CMD( |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 85 | bmp, 5, 1, do_bmp, |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 86 | "bmp - manipulate BMP image data\n", |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 87 | "info <imageAddr> - display image info\n" |
| 88 | "bmp display <imageAddr> [x y] - display image at x,y\n" |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 89 | ); |
| 90 | |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 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; |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 104 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 105 | unsigned char *dst = NULL; |
| 106 | ulong len; |
| 107 | #endif /* CONFIG_VIDEO_BMP_GZIP */ |
| 108 | |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 109 | if (!((bmp->header.signature[0]=='B') && |
| 110 | (bmp->header.signature[1]=='M'))) { |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 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 */ |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 147 | printf("There is no valid bmp file at the given address\n"); |
| 148 | return(1); |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 149 | #endif /* CONFIG_VIDEO_BMP_GZIP */ |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 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)); |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 155 | |
| 156 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 157 | if (dst) { |
| 158 | free(dst); |
| 159 | } |
| 160 | #endif /* CONFIG_VIDEO_BMP_GZIP */ |
| 161 | |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 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 | */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 175 | static int bmp_display(ulong addr, int x, int y) |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 176 | { |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 177 | #if defined(CONFIG_LCD) |
| 178 | extern int lcd_display_bitmap (ulong, int, int); |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 179 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 180 | return (lcd_display_bitmap (addr, x, y)); |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 181 | #elif defined(CONFIG_VIDEO) |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 182 | extern int video_display_bitmap (ulong, int, int); |
| 183 | return (video_display_bitmap (addr, x, y)); |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 184 | #else |
| 185 | # error bmp_display() requires CONFIG_LCD or CONFIG_VIDEO |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 186 | #endif |
wdenk | 059ae17 | 2003-04-20 16:52:09 +0000 | [diff] [blame] | 187 | } |