Tedd OKANO / Mbed 2 deprecated MARY_CAMERA_Hello

Dependencies:   MARY_CAMERA NokiaLCD mbed

Committer:
okano
Date:
Tue Mar 11 03:29:01 2014 +0000
Revision:
22:d5e24ab4afb7
Parent:
11:149993faf2be
Child:
23:8471197d3096
test code

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 10:3c8fc9569377 57 int open_BMP( char *file_name )
okano 10:3c8fc9569377 58 {
okano 11:149993faf2be 59 #ifdef RGB565_FORMAT
okano 11:149993faf2be 60 #else
okano 11:149993faf2be 61 #if 1
okano 11:149993faf2be 62 bmp_header bh = {
okano 11:149993faf2be 63 0x4D42,
okano 22:d5e24ab4afb7 64 MARY_CAMERA::PIXEL_PER_LINE * MARY_CAMERA::LINE_PER_FRAME * 4 + 54,
okano 11:149993faf2be 65 0,
okano 11:149993faf2be 66 0,
okano 11:149993faf2be 67 54,
okano 11:149993faf2be 68 40,
okano 22:d5e24ab4afb7 69 MARY_CAMERA::PIXEL_PER_LINE,
okano 22:d5e24ab4afb7 70 MARY_CAMERA::LINE_PER_FRAME,
okano 11:149993faf2be 71 1,
okano 11:149993faf2be 72 32,
okano 11:149993faf2be 73 0,
okano 22:d5e24ab4afb7 74 MARY_CAMERA::PIXEL_PER_LINE * MARY_CAMERA::LINE_PER_FRAME * 4,
okano 11:149993faf2be 75 2835,
okano 11:149993faf2be 76 2835,
okano 11:149993faf2be 77 0,
okano 11:149993faf2be 78 0
okano 11:149993faf2be 79 };
okano 11:149993faf2be 80
okano 11:149993faf2be 81 bmp_header *bhp = &bh;
okano 11:149993faf2be 82 #endif
okano 11:149993faf2be 83 #endif
okano 11:149993faf2be 84
okano 11:149993faf2be 85
okano 10:3c8fc9569377 86 char s[ 80 ];
okano 10:3c8fc9569377 87
okano 10:3c8fc9569377 88 sprintf( s, "/local/%s", file_name );
okano 10:3c8fc9569377 89
okano 10:3c8fc9569377 90 if ( NULL == (fp = fopen( s, "wb" )) )
okano 10:3c8fc9569377 91 return 1;
okano 10:3c8fc9569377 92
okano 11:149993faf2be 93 fwrite( &bh, sizeof( bh ), 1, fp );
okano 11:149993faf2be 94 // fwrite( bhp, sizeof( bhp ), 1, fp );
okano 10:3c8fc9569377 95
okano 10:3c8fc9569377 96 return 0;
okano 10:3c8fc9569377 97 }
okano 10:3c8fc9569377 98
okano 10:3c8fc9569377 99 void write_BMP( short *p, int length )
okano 10:3c8fc9569377 100 {
okano 11:149993faf2be 101 #ifdef RGB565_FORMAT
okano 10:3c8fc9569377 102 fwrite( p, sizeof( short ), length, fp );
okano 11:149993faf2be 103 #else
okano 11:149993faf2be 104 unsigned long v[ length ];
okano 11:149993faf2be 105 unsigned long tmp;
okano 11:149993faf2be 106
okano 11:149993faf2be 107 for ( int i = 0; i < length; i++ )
okano 11:149993faf2be 108 {
okano 11:149993faf2be 109 tmp = p[ i ];
okano 11:149993faf2be 110 v[ i ] = (tmp & 0x001F) << 3;
okano 11:149993faf2be 111 v[ i ] |= (tmp & 0x07E0) << 5;
okano 11:149993faf2be 112 v[ i ] |= (tmp & 0xF800) << 8;
okano 11:149993faf2be 113 }
okano 11:149993faf2be 114
okano 11:149993faf2be 115 fwrite( v, sizeof( unsigned long ), length, fp );
okano 11:149993faf2be 116 #endif
okano 10:3c8fc9569377 117 }
okano 10:3c8fc9569377 118
okano 10:3c8fc9569377 119 void close_BMP( void )
okano 10:3c8fc9569377 120 {
okano 10:3c8fc9569377 121 fclose( fp );
okano 10:3c8fc9569377 122 }