Tedd OKANO / Mbed 2 deprecated MARY_CAMERA_Hello

Dependencies:   MARY_CAMERA NokiaLCD mbed

Committer:
okano
Date:
Tue Feb 18 06:50:13 2014 +0000
Revision:
11:149993faf2be
Parent:
10:3c8fc9569377
Child:
22:d5e24ab4afb7
bmp 32bit format file save function added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 10:3c8fc9569377 1 #include "mbed.h" // for mbed
okano 10:3c8fc9569377 2 LocalFileSystem local("local"); // for mbed to access local file system
okano 10:3c8fc9569377 3
okano 11:149993faf2be 4
okano 11:149993faf2be 5 #ifdef RGB565_FORMAT
okano 11:149993faf2be 6 char bhp[] = {
okano 10:3c8fc9569377 7 0x42, 0x4d, 0x8a, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00,
okano 10:3c8fc9569377 8 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00,
okano 10:3c8fc9569377 9 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00,
okano 10:3c8fc9569377 10 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x1f, 0x00,
okano 10:3c8fc9569377 11 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
okano 10:3c8fc9569377 12 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
okano 10:3c8fc9569377 13 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
okano 10:3c8fc9569377 14 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
okano 10:3c8fc9569377 15 };
okano 11:149993faf2be 16 #else
okano 11:149993faf2be 17 #if 0
okano 11:149993faf2be 18 char bhp[] = {
okano 11:149993faf2be 19 0x42, 0x4d, 0x8a, 0x8c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00,
okano 11:149993faf2be 20 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x03, 0x00,
okano 11:149993faf2be 21 0x00, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00,
okano 11:149993faf2be 22 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
okano 11:149993faf2be 23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
okano 11:149993faf2be 24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
okano 11:149993faf2be 25 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
okano 11:149993faf2be 26 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
okano 11:149993faf2be 27 };
okano 11:149993faf2be 28
okano 11:149993faf2be 29 #else
okano 11:149993faf2be 30 typedef struct bmp_header_st {
okano 11:149993faf2be 31 unsigned short bfType __attribute__((packed));
okano 11:149993faf2be 32 unsigned long bfSize __attribute__((packed));
okano 11:149993faf2be 33 unsigned short bfReserved1 __attribute__((packed));
okano 11:149993faf2be 34 unsigned short bfReserved2 __attribute__((packed));
okano 11:149993faf2be 35 unsigned long bfOffBits __attribute__((packed));
okano 11:149993faf2be 36
okano 11:149993faf2be 37 unsigned long biSize __attribute__((packed));
okano 11:149993faf2be 38 long biWidth __attribute__((packed));
okano 11:149993faf2be 39 long biHeight __attribute__((packed));
okano 11:149993faf2be 40 unsigned short biPlanes __attribute__((packed));
okano 11:149993faf2be 41 unsigned short biBitCount __attribute__((packed));
okano 11:149993faf2be 42 unsigned long biCompression __attribute__((packed));
okano 11:149993faf2be 43 unsigned long biSizeImage __attribute__((packed));
okano 11:149993faf2be 44 long biXPixPerMeter __attribute__((packed));
okano 11:149993faf2be 45 long biYPixPerMeter __attribute__((packed));
okano 11:149993faf2be 46 unsigned long biClrUsed __attribute__((packed));
okano 11:149993faf2be 47 unsigned long biCirImportant __attribute__((packed));
okano 11:149993faf2be 48 }
okano 11:149993faf2be 49 bmp_header;
okano 11:149993faf2be 50 #endif
okano 11:149993faf2be 51 #endif
okano 10:3c8fc9569377 52
okano 10:3c8fc9569377 53 FILE *fp;
okano 10:3c8fc9569377 54
okano 10:3c8fc9569377 55 int open_BMP( char *file_name )
okano 10:3c8fc9569377 56 {
okano 11:149993faf2be 57 #ifdef RGB565_FORMAT
okano 11:149993faf2be 58 #else
okano 11:149993faf2be 59 #if 1
okano 11:149993faf2be 60 bmp_header bh = {
okano 11:149993faf2be 61 0x4D42,
okano 11:149993faf2be 62 176 * 144 * 4 + 54,
okano 11:149993faf2be 63 0,
okano 11:149993faf2be 64 0,
okano 11:149993faf2be 65 54,
okano 11:149993faf2be 66 40,
okano 11:149993faf2be 67 176,
okano 11:149993faf2be 68 144,
okano 11:149993faf2be 69 1,
okano 11:149993faf2be 70 32,
okano 11:149993faf2be 71 0,
okano 11:149993faf2be 72 176 * 144 * 4,
okano 11:149993faf2be 73 2835,
okano 11:149993faf2be 74 2835,
okano 11:149993faf2be 75 0,
okano 11:149993faf2be 76 0
okano 11:149993faf2be 77 };
okano 11:149993faf2be 78
okano 11:149993faf2be 79 bmp_header *bhp = &bh;
okano 11:149993faf2be 80 #endif
okano 11:149993faf2be 81 #endif
okano 11:149993faf2be 82
okano 11:149993faf2be 83
okano 10:3c8fc9569377 84 char s[ 80 ];
okano 10:3c8fc9569377 85
okano 10:3c8fc9569377 86 sprintf( s, "/local/%s", file_name );
okano 10:3c8fc9569377 87
okano 10:3c8fc9569377 88 if ( NULL == (fp = fopen( s, "wb" )) )
okano 10:3c8fc9569377 89 return 1;
okano 10:3c8fc9569377 90
okano 11:149993faf2be 91 fwrite( &bh, sizeof( bh ), 1, fp );
okano 11:149993faf2be 92 // fwrite( bhp, sizeof( bhp ), 1, fp );
okano 10:3c8fc9569377 93
okano 10:3c8fc9569377 94 return 0;
okano 10:3c8fc9569377 95 }
okano 10:3c8fc9569377 96
okano 10:3c8fc9569377 97 void write_BMP( short *p, int length )
okano 10:3c8fc9569377 98 {
okano 11:149993faf2be 99 #ifdef RGB565_FORMAT
okano 10:3c8fc9569377 100 fwrite( p, sizeof( short ), length, fp );
okano 11:149993faf2be 101 #else
okano 11:149993faf2be 102 unsigned long v[ length ];
okano 11:149993faf2be 103 unsigned long tmp;
okano 11:149993faf2be 104
okano 11:149993faf2be 105 for ( int i = 0; i < length; i++ )
okano 11:149993faf2be 106 {
okano 11:149993faf2be 107 tmp = p[ i ];
okano 11:149993faf2be 108 v[ i ] = (tmp & 0x001F) << 3;
okano 11:149993faf2be 109 v[ i ] |= (tmp & 0x07E0) << 5;
okano 11:149993faf2be 110 v[ i ] |= (tmp & 0xF800) << 8;
okano 11:149993faf2be 111 }
okano 11:149993faf2be 112
okano 11:149993faf2be 113 fwrite( v, sizeof( unsigned long ), length, fp );
okano 11:149993faf2be 114 #endif
okano 10:3c8fc9569377 115 }
okano 10:3c8fc9569377 116
okano 10:3c8fc9569377 117 void close_BMP( void )
okano 10:3c8fc9569377 118 {
okano 10:3c8fc9569377 119 fclose( fp );
okano 10:3c8fc9569377 120 }