![](/media/cache/group/site_id.gif.50x50_q85.jpg)
MARMEX_VB test application program. This application works on "mbed NXP LPC1768" only. This application expects to have the MARMEX_VB module on a "MAPLE mini type-B (MARM03-BASE)" baseboard (slot2) with MARMEX_OB module (on slot1)
Dependencies: MARMEX_VB NokiaLCD mbed
This is the library test program.
The program can test features of the library (refer to MARMEX-VB's API document) and can save captured data into BMP file.
Warning!
This test program can run on "mbed NXP LPC1768" only.
Picture : sample of test program operation
The modules of MARMEX-VB and MARMEX-OB are set on the "MAPLE mini type-B (MARM03-BASE)" baseboard.
The image data from camera is mirrored and alpha graphics added by software.
bmp_handler.cpp@0:343c01965543, 2014-06-06 (annotated)
- Committer:
- nxpfan
- Date:
- Fri Jun 06 03:37:02 2014 +0000
- Revision:
- 0:343c01965543
version 0.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nxpfan | 0:343c01965543 | 1 | #include "mbed.h" // for mbed |
nxpfan | 0:343c01965543 | 2 | #include "MARMEX_VB.h" |
nxpfan | 0:343c01965543 | 3 | #include "bmp_handler.h" |
nxpfan | 0:343c01965543 | 4 | |
nxpfan | 0:343c01965543 | 5 | #if defined( TARGET_MBED_LPC1768 ) || defined( TARGET_LPC11U24_401 ) |
nxpfan | 0:343c01965543 | 6 | LocalFileSystem local("local"); // for mbed to access local file system |
nxpfan | 0:343c01965543 | 7 | #endif |
nxpfan | 0:343c01965543 | 8 | |
nxpfan | 0:343c01965543 | 9 | #ifdef RGB565_FORMAT |
nxpfan | 0:343c01965543 | 10 | char bhp[] = { |
nxpfan | 0:343c01965543 | 11 | 0x42, 0x4d, 0x8a, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00, |
nxpfan | 0:343c01965543 | 12 | 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00, |
nxpfan | 0:343c01965543 | 13 | 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00, |
nxpfan | 0:343c01965543 | 14 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x1f, 0x00, |
nxpfan | 0:343c01965543 | 15 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
nxpfan | 0:343c01965543 | 16 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
nxpfan | 0:343c01965543 | 17 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
nxpfan | 0:343c01965543 | 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
nxpfan | 0:343c01965543 | 19 | }; |
nxpfan | 0:343c01965543 | 20 | #else |
nxpfan | 0:343c01965543 | 21 | #if 0 |
nxpfan | 0:343c01965543 | 22 | char bhp[] = { |
nxpfan | 0:343c01965543 | 23 | 0x42, 0x4d, 0x8a, 0x8c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00, |
nxpfan | 0:343c01965543 | 24 | 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x03, 0x00, |
nxpfan | 0:343c01965543 | 25 | 0x00, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00, |
nxpfan | 0:343c01965543 | 26 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, |
nxpfan | 0:343c01965543 | 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
nxpfan | 0:343c01965543 | 28 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
nxpfan | 0:343c01965543 | 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
nxpfan | 0:343c01965543 | 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
nxpfan | 0:343c01965543 | 31 | }; |
nxpfan | 0:343c01965543 | 32 | |
nxpfan | 0:343c01965543 | 33 | #else |
nxpfan | 0:343c01965543 | 34 | typedef struct bmp_header_st { |
nxpfan | 0:343c01965543 | 35 | unsigned short bfType __attribute__((packed)); |
nxpfan | 0:343c01965543 | 36 | unsigned long bfSize __attribute__((packed)); |
nxpfan | 0:343c01965543 | 37 | unsigned short bfReserved1 __attribute__((packed)); |
nxpfan | 0:343c01965543 | 38 | unsigned short bfReserved2 __attribute__((packed)); |
nxpfan | 0:343c01965543 | 39 | unsigned long bfOffBits __attribute__((packed)); |
nxpfan | 0:343c01965543 | 40 | |
nxpfan | 0:343c01965543 | 41 | unsigned long biSize __attribute__((packed)); |
nxpfan | 0:343c01965543 | 42 | long biWidth __attribute__((packed)); |
nxpfan | 0:343c01965543 | 43 | long biHeight __attribute__((packed)); |
nxpfan | 0:343c01965543 | 44 | unsigned short biPlanes __attribute__((packed)); |
nxpfan | 0:343c01965543 | 45 | unsigned short biBitCount __attribute__((packed)); |
nxpfan | 0:343c01965543 | 46 | unsigned long biCompression __attribute__((packed)); |
nxpfan | 0:343c01965543 | 47 | unsigned long biSizeImage __attribute__((packed)); |
nxpfan | 0:343c01965543 | 48 | long biXPixPerMeter __attribute__((packed)); |
nxpfan | 0:343c01965543 | 49 | long biYPixPerMeter __attribute__((packed)); |
nxpfan | 0:343c01965543 | 50 | unsigned long biClrUsed __attribute__((packed)); |
nxpfan | 0:343c01965543 | 51 | unsigned long biCirImportant __attribute__((packed)); |
nxpfan | 0:343c01965543 | 52 | } |
nxpfan | 0:343c01965543 | 53 | bmp_header; |
nxpfan | 0:343c01965543 | 54 | #endif |
nxpfan | 0:343c01965543 | 55 | #endif |
nxpfan | 0:343c01965543 | 56 | |
nxpfan | 0:343c01965543 | 57 | |
nxpfan | 0:343c01965543 | 58 | FILE *fp; |
nxpfan | 0:343c01965543 | 59 | |
nxpfan | 0:343c01965543 | 60 | int open_BMP( char *file_name, int get_horizontal_size, int get_vertical_size ) |
nxpfan | 0:343c01965543 | 61 | { |
nxpfan | 0:343c01965543 | 62 | bmp_header bh = { |
nxpfan | 0:343c01965543 | 63 | 0x4D42, |
nxpfan | 0:343c01965543 | 64 | get_horizontal_size * get_vertical_size * 4 + 54, |
nxpfan | 0:343c01965543 | 65 | 0, |
nxpfan | 0:343c01965543 | 66 | 0, |
nxpfan | 0:343c01965543 | 67 | 54, |
nxpfan | 0:343c01965543 | 68 | 40, |
nxpfan | 0:343c01965543 | 69 | get_horizontal_size, |
nxpfan | 0:343c01965543 | 70 | get_vertical_size, |
nxpfan | 0:343c01965543 | 71 | 1, |
nxpfan | 0:343c01965543 | 72 | 32, |
nxpfan | 0:343c01965543 | 73 | 0, |
nxpfan | 0:343c01965543 | 74 | get_horizontal_size * get_vertical_size * 4, |
nxpfan | 0:343c01965543 | 75 | 2835, |
nxpfan | 0:343c01965543 | 76 | 2835, |
nxpfan | 0:343c01965543 | 77 | 0, |
nxpfan | 0:343c01965543 | 78 | 0 |
nxpfan | 0:343c01965543 | 79 | }; |
nxpfan | 0:343c01965543 | 80 | char s[ 80 ]; |
nxpfan | 0:343c01965543 | 81 | |
nxpfan | 0:343c01965543 | 82 | sprintf( s, "/local/%s", file_name ); |
nxpfan | 0:343c01965543 | 83 | |
nxpfan | 0:343c01965543 | 84 | if ( NULL == (fp = fopen( s, "wb" )) ) |
nxpfan | 0:343c01965543 | 85 | return 1; |
nxpfan | 0:343c01965543 | 86 | |
nxpfan | 0:343c01965543 | 87 | fwrite( &bh, sizeof( bh ), 1, fp ); |
nxpfan | 0:343c01965543 | 88 | // fwrite( bhp, sizeof( bhp ), 1, fp ); |
nxpfan | 0:343c01965543 | 89 | |
nxpfan | 0:343c01965543 | 90 | return 0; |
nxpfan | 0:343c01965543 | 91 | } |
nxpfan | 0:343c01965543 | 92 | |
nxpfan | 0:343c01965543 | 93 | void write_BMP( short *p, int length ) |
nxpfan | 0:343c01965543 | 94 | { |
nxpfan | 0:343c01965543 | 95 | #ifdef RGB565_FORMAT |
nxpfan | 0:343c01965543 | 96 | fwrite( p, sizeof( short ), length, fp ); |
nxpfan | 0:343c01965543 | 97 | #else |
nxpfan | 0:343c01965543 | 98 | unsigned long v[ length ]; |
nxpfan | 0:343c01965543 | 99 | unsigned long tmp; |
nxpfan | 0:343c01965543 | 100 | |
nxpfan | 0:343c01965543 | 101 | for ( int i = 0; i < length; i++ ) { |
nxpfan | 0:343c01965543 | 102 | tmp = p[ i ]; |
nxpfan | 0:343c01965543 | 103 | //tmp = 0xF800; |
nxpfan | 0:343c01965543 | 104 | v[ i ] = (tmp & 0x001F) << 3; |
nxpfan | 0:343c01965543 | 105 | v[ i ] |= (tmp & 0x07E0) << 5; |
nxpfan | 0:343c01965543 | 106 | v[ i ] |= (tmp & 0xF800) << 8; |
nxpfan | 0:343c01965543 | 107 | } |
nxpfan | 0:343c01965543 | 108 | |
nxpfan | 0:343c01965543 | 109 | fwrite( v, sizeof( unsigned long ), length, fp ); |
nxpfan | 0:343c01965543 | 110 | #endif |
nxpfan | 0:343c01965543 | 111 | } |
nxpfan | 0:343c01965543 | 112 | |
nxpfan | 0:343c01965543 | 113 | void write_BMP( short *p, int length, char mask ) |
nxpfan | 0:343c01965543 | 114 | { |
nxpfan | 0:343c01965543 | 115 | unsigned long v[ length ]; |
nxpfan | 0:343c01965543 | 116 | unsigned long tmp; |
nxpfan | 0:343c01965543 | 117 | |
nxpfan | 0:343c01965543 | 118 | for ( int i = 0; i < length; i++ ) { |
nxpfan | 0:343c01965543 | 119 | tmp = p[ i ]; |
nxpfan | 0:343c01965543 | 120 | //tmp = 0xF800; |
nxpfan | 0:343c01965543 | 121 | v[ i ] = (mask & 0x4) ? (tmp & 0x001F) << 3 : 0; |
nxpfan | 0:343c01965543 | 122 | v[ i ] |= (mask & 0x2) ? (tmp & 0x07E0) << 5 : 0; |
nxpfan | 0:343c01965543 | 123 | v[ i ] |= (mask & 0x1) ? (tmp & 0xF800) << 8 : 0; |
nxpfan | 0:343c01965543 | 124 | } |
nxpfan | 0:343c01965543 | 125 | |
nxpfan | 0:343c01965543 | 126 | fwrite( v, sizeof( unsigned long ), length, fp ); |
nxpfan | 0:343c01965543 | 127 | } |
nxpfan | 0:343c01965543 | 128 | |
nxpfan | 0:343c01965543 | 129 | void close_BMP( void ) |
nxpfan | 0:343c01965543 | 130 | { |
nxpfan | 0:343c01965543 | 131 | fclose( fp ); |
nxpfan | 0:343c01965543 | 132 | } |
nxpfan | 0:343c01965543 | 133 | |
nxpfan | 0:343c01965543 | 134 | |
nxpfan | 0:343c01965543 | 135 | char *read_alpha_BMP( char *file_name, alpha_param *azp ) |
nxpfan | 0:343c01965543 | 136 | { |
nxpfan | 0:343c01965543 | 137 | bmp_header bh; |
nxpfan | 0:343c01965543 | 138 | char s[ 80 ]; |
nxpfan | 0:343c01965543 | 139 | int data_size; |
nxpfan | 0:343c01965543 | 140 | |
nxpfan | 0:343c01965543 | 141 | sprintf( s, "/local/%s", file_name ); |
nxpfan | 0:343c01965543 | 142 | |
nxpfan | 0:343c01965543 | 143 | if ( NULL == (fp = fopen( s, "rb" )) ) { |
nxpfan | 0:343c01965543 | 144 | azp->buffer = NULL; |
nxpfan | 0:343c01965543 | 145 | return NULL; |
nxpfan | 0:343c01965543 | 146 | } |
nxpfan | 0:343c01965543 | 147 | |
nxpfan | 0:343c01965543 | 148 | fread( &bh, sizeof( bh ), 1, fp ); |
nxpfan | 0:343c01965543 | 149 | azp->h = bh.biWidth; |
nxpfan | 0:343c01965543 | 150 | azp->v = bh.biHeight; |
nxpfan | 0:343c01965543 | 151 | azp->byte_per_pixel = bh.biBitCount / 8; |
nxpfan | 0:343c01965543 | 152 | |
nxpfan | 0:343c01965543 | 153 | data_size = sizeof( char ) * azp->h * azp->v * azp->byte_per_pixel; |
nxpfan | 0:343c01965543 | 154 | |
nxpfan | 0:343c01965543 | 155 | fseek( fp, bh.bfOffBits - sizeof( bh ), SEEK_CUR ); |
nxpfan | 0:343c01965543 | 156 | |
nxpfan | 0:343c01965543 | 157 | if ( NULL == ( azp->buffer = (char *)malloc( data_size ) ) ) { |
nxpfan | 0:343c01965543 | 158 | fclose( fp ); |
nxpfan | 0:343c01965543 | 159 | return ( NULL ); |
nxpfan | 0:343c01965543 | 160 | } |
nxpfan | 0:343c01965543 | 161 | |
nxpfan | 0:343c01965543 | 162 | fread( azp->buffer, data_size, 1, fp ); |
nxpfan | 0:343c01965543 | 163 | fclose( fp ); |
nxpfan | 0:343c01965543 | 164 | |
nxpfan | 0:343c01965543 | 165 | printf( "alpha image loaded. (from \"%s\", size = %d/%d, %d bytes/pixel)\r\n", s, azp->h, azp->v, azp->byte_per_pixel ); |
nxpfan | 0:343c01965543 | 166 | |
nxpfan | 0:343c01965543 | 167 | return azp->buffer; |
nxpfan | 0:343c01965543 | 168 | } |