Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MARY_CAMERA NokiaLCD mbed
bmp_handler.cpp
- Committer:
- okano
- Date:
- 2014-03-11
- Revision:
- 22:d5e24ab4afb7
- Parent:
- 11:149993faf2be
- Child:
- 23:8471197d3096
File content as of revision 22:d5e24ab4afb7:
#include "mbed.h" // for mbed
#include "MARY_CAMERA.h"
LocalFileSystem local("local"); // for mbed to access local file system
#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,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x1f, 0x00,
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
#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,
MARY_CAMERA::PIXEL_PER_LINE * MARY_CAMERA::LINE_PER_FRAME * 4 + 54,
0,
0,
54,
40,
MARY_CAMERA::PIXEL_PER_LINE,
MARY_CAMERA::LINE_PER_FRAME,
1,
32,
0,
MARY_CAMERA::PIXEL_PER_LINE * MARY_CAMERA::LINE_PER_FRAME * 4,
2835,
2835,
0,
0
};
bmp_header *bhp = &bh;
#endif
#endif
char s[ 80 ];
sprintf( s, "/local/%s", file_name );
if ( NULL == (fp = fopen( s, "wb" )) )
return 1;
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 )
{
fclose( fp );
}