Tedd OKANO / Mbed 2 deprecated MARY_CAMERA_Hello

Dependencies:   MARY_CAMERA NokiaLCD mbed

Committer:
okano
Date:
Tue Mar 11 07:51:22 2014 +0000
Revision:
23:8471197d3096
Parent:
22:d5e24ab4afb7
Child:
28:ef40d40b5d39
size changed enabled

Who changed what in which revision?

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