Tedd OKANO / Mbed 2 deprecated MARY_CAMERA_Hello

Dependencies:   MARY_CAMERA NokiaLCD mbed

Committer:
okano
Date:
Thu Mar 13 04:44:50 2014 +0000
Revision:
28:ef40d40b5d39
Parent:
23:8471197d3096
test code for contouring problem

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