Tedd OKANO / Mbed 2 deprecated MARY_CAMERA_Hello

Dependencies:   MARY_CAMERA NokiaLCD mbed

Revision:
11:149993faf2be
Parent:
10:3c8fc9569377
Child:
22:d5e24ab4afb7
diff -r 3c8fc9569377 -r 149993faf2be bmp_handler.cpp
--- a/bmp_handler.cpp	Tue Feb 18 05:03:58 2014 +0000
+++ b/bmp_handler.cpp	Tue Feb 18 06:50:13 2014 +0000
@@ -1,7 +1,9 @@
 #include "mbed.h"                   //  for mbed
 LocalFileSystem     local("local"); //  for mbed to access local file system
 
-char bmp_header[]   = {
+
+#ifdef  RGB565_FORMAT
+char bhp[]   = {
     0x42, 0x4d, 0x8a, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00,
     0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00,
     0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00,
@@ -11,11 +13,74 @@
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
+#else
+#if 0
+char bhp[]   = {
+    0x42, 0x4d, 0x8a, 0x8c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00,
+    0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x03, 0x00,
+    0x00, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+#else
+typedef struct  bmp_header_st    {
+    unsigned short  bfType            __attribute__((packed));
+    unsigned long   bfSize            __attribute__((packed));
+    unsigned short  bfReserved1       __attribute__((packed));
+    unsigned short  bfReserved2       __attribute__((packed));
+    unsigned long   bfOffBits         __attribute__((packed));
+
+    unsigned long   biSize            __attribute__((packed));
+    long            biWidth           __attribute__((packed));
+    long            biHeight          __attribute__((packed));
+    unsigned short  biPlanes          __attribute__((packed));
+    unsigned short  biBitCount        __attribute__((packed));
+    unsigned long   biCompression     __attribute__((packed));
+    unsigned long   biSizeImage       __attribute__((packed));
+    long            biXPixPerMeter    __attribute__((packed));
+    long            biYPixPerMeter    __attribute__((packed));
+    unsigned long   biClrUsed         __attribute__((packed));
+    unsigned long   biCirImportant    __attribute__((packed));
+}
+bmp_header;
+#endif
+#endif
 
 FILE    *fp;
 
 int open_BMP( char *file_name )
 {
+#ifdef  RGB565_FORMAT
+#else
+#if 1
+    bmp_header  bh  =   {
+        0x4D42,
+        176 * 144 * 4 + 54,
+        0,
+        0,
+        54,
+        40,
+        176,
+        144,
+        1,
+        32,
+        0,
+        176 * 144 * 4,
+        2835,
+        2835,
+        0,
+        0
+    };
+
+    bmp_header  *bhp = &bh;
+    #endif
+#endif
+
+
     char    s[ 80 ];
 
     sprintf( s, "/local/%s", file_name );
@@ -23,14 +88,30 @@
     if ( NULL == (fp    = fopen( s, "wb" )) )
         return 1;
 
-    fwrite( bmp_header, sizeof( bmp_header ), 1, fp );
+    fwrite( &bh, sizeof( bh ), 1, fp );
+//    fwrite( bhp, sizeof( bhp ), 1, fp );
 
     return 0;
 }
 
 void write_BMP( short *p, int length )
 {
+#ifdef  RGB565_FORMAT
     fwrite( p, sizeof( short ), length, fp );
+#else
+    unsigned long   v[ length ];
+    unsigned long   tmp;
+
+    for ( int i = 0; i < length; i++ )
+    {
+        tmp     = p[ i ];
+        v[ i ]  = (tmp & 0x001F) << 3;
+        v[ i ] |= (tmp & 0x07E0) << 5;
+        v[ i ] |= (tmp & 0xF800) << 8;
+    }
+
+    fwrite( v, sizeof( unsigned long ), length, fp );
+#endif
 }
 
 void close_BMP( void )