Commit 059ae173e93a4a0aa698ce1e2d87d33cc55cf8c0

Authored by wdenk
1 parent 824a1ebffe

Add files needed for bitmap load support

Showing 3 changed files with 239 additions and 0 deletions Side-by-side Diff

  1 +/*
  2 + * (C) Copyright 2002
  3 + * Dtlev 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 +
  32 +#if (CONFIG_COMMANDS & CFG_CMD_BMP)
  33 +
  34 +static int bmp_info (ulong addr);
  35 +static int bmp_display (ulong addr);
  36 +
  37 +/*
  38 + * Subroutine: do_bmp
  39 + *
  40 + * Description: Handler for 'bmp' command..
  41 + *
  42 + * Inputs: argv[1] contains the subcommand
  43 + *
  44 + * Return: None
  45 + *
  46 + */
  47 +int do_bmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  48 +{
  49 + ulong addr;
  50 +
  51 + switch (argc) {
  52 + case 2: /* use load_addr as default address */
  53 + addr = load_addr;
  54 + break;
  55 + case 3: /* use argument */
  56 + addr = simple_strtoul(argv[2], NULL, 16);
  57 + break;
  58 + default:
  59 + printf ("Usage:\n%s\n", cmdtp->usage);
  60 + return 1;
  61 + }
  62 +
  63 + /* Allow for short names
  64 + * Adjust length if more sub-commands get added
  65 + */
  66 + if (strncmp(argv[1],"info",1) == 0) {
  67 + return (bmp_info(addr));
  68 + } else if (strncmp(argv[1],"display",1) == 0) {
  69 + return (bmp_display(addr));
  70 + } else {
  71 + printf ("Usage:\n%s\n", cmdtp->usage);
  72 + return 1;
  73 + }
  74 +}
  75 +
  76 +/*
  77 + * Subroutine: bmp_info
  78 + *
  79 + * Description: Show information about bmp file in memory
  80 + *
  81 + * Inputs: addr address of the bmp file
  82 + *
  83 + * Return: None
  84 + *
  85 + */
  86 +static int bmp_info(ulong addr)
  87 +{
  88 + bmp_image_t *bmp=(bmp_image_t *)addr;
  89 + if (!((bmp->header.signature[0]=='B') &&
  90 + (bmp->header.signature[1]=='M'))) {
  91 + printf("There is no valid bmp file at the given address\n");
  92 + return(1);
  93 + }
  94 + printf("Image size : %d x %d\n", le32_to_cpu(bmp->header.width),
  95 + le32_to_cpu(bmp->header.height));
  96 + printf("Bits per pixel: %d\n", le16_to_cpu(bmp->header.bit_count));
  97 + printf("Compression : %d\n", le32_to_cpu(bmp->header.compression));
  98 + return(0);
  99 +}
  100 +
  101 +/*
  102 + * Subroutine: bmp_display
  103 + *
  104 + * Description: Display bmp file located in memory
  105 + *
  106 + * Inputs: addr address of the bmp file
  107 + *
  108 + * Return: None
  109 + *
  110 + */
  111 +static int bmp_display(ulong addr)
  112 +{
  113 + extern int lcd_display_bitmap (ulong);
  114 +
  115 + return (lcd_display_bitmap (addr));
  116 +}
  117 +
  118 +#endif /* (CONFIG_COMMANDS & CFG_CMD_BMP) */
include/bmp_layout.h
  1 +/* (C) Copyright 2002
  2 + * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
  3 + *
  4 + * See file CREDITS for list of people who contributed to this
  5 + * project.
  6 + *
  7 + * This program is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU General Public License as
  9 + * published by the Free Software Foundation; either version 2 of
  10 + * the License, or (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20 + * MA 02111-1307 USA
  21 + */
  22 +
  23 +/************************************************************************/
  24 +/* ** Layout of a bmp file */
  25 +/************************************************************************/
  26 +
  27 +#ifndef _BMP_H_
  28 +#define _BMP_H_
  29 +
  30 +typedef struct bmp_color_table_entry {
  31 + __u8 blue;
  32 + __u8 green;
  33 + __u8 red;
  34 + __u8 reserved;
  35 +} __attribute__((packed)) bmp_color_table_entry_t;
  36 +
  37 +/* When accessing these fields, remember that they are stored in little
  38 + endian format, so use linux macros, e.g. le32_to_cpu(width) */
  39 +
  40 +typedef struct bmp_header {
  41 + /* Header */
  42 + char signature[2];
  43 + __u32 file_size;
  44 + __u32 reserved;
  45 + __u32 data_offset;
  46 + /* InfoHeader */
  47 + __u32 size;
  48 + __u32 width;
  49 + __u32 height;
  50 + __u16 planes;
  51 + __u16 bit_count;
  52 + __u32 compression;
  53 + __u32 image_size;
  54 + __u32 x_pixels_per_m;
  55 + __u32 y_pixels_per_m;
  56 + __u32 colors_used;
  57 + __u32 colors_important;
  58 + /* ColorTable */
  59 +
  60 +} __attribute__((packed)) bmp_header_t;
  61 +
  62 +typedef struct bmp_image {
  63 + bmp_header_t header;
  64 + /* We use a zero sized array just as a placeholder for variable
  65 + sized array */
  66 + bmp_color_table_entry_t color_table[0];
  67 +} bmp_image_t;
  68 +
  69 +/* Data in the bmp_image is aligned to this length */
  70 +#define BMP_DATA_ALIGN 4
  71 +
  72 +/* Constants for the compression field */
  73 +#define BMP_BI_RGB 0
  74 +#define BMP_BI_RLE8 1
  75 +#define BMP_BI_RLE4 2
  76 +
  77 +#endif /* _BMP_H_ */
  1 +/* (C) Copyright 2002
  2 + * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
  3 + *
  4 + * This program is free software; you can redistribute it and/or
  5 + * modify it under the terms of the GNU General Public License as
  6 + * published by the Free Software Foundation; either version 2 of
  7 + * the License, or (at your option) any later version.
  8 + *
  9 + * This program is distributed in the hope that it will be useful,
  10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 + * GNU General Public License for more details.
  13 + *
  14 + * You should have received a copy of the GNU General Public License
  15 + * along with this program; if not, write to the Free Software
  16 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17 + * MA 02111-1307 USA
  18 + */
  19 +
  20 +/*
  21 + * Bitmap display support
  22 + */
  23 +#ifndef _CMD_BMP_H
  24 +#define _CMD_BMP_H
  25 +
  26 +#include <common.h>
  27 +#include <command.h>
  28 +
  29 +
  30 +#if (CONFIG_COMMANDS & CFG_CMD_BMP)
  31 +
  32 +#define CMD_TBL_BMP MK_CMD_TBL_ENTRY( \
  33 + "bmp", 3, 3, 1, do_bmp, \
  34 + "bmp - manipulate BMP image data\n", \
  35 + "\nbmp info <imageAddr> - display image info\n" \
  36 + "bmp display <imageAddr> - display image\n" \
  37 +),
  38 +int do_bmp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  39 +
  40 +#else
  41 +#define CMD_TBL_BMP
  42 +#endif
  43 +
  44 +#endif /* _CMD_BMP_H */