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: BaseJpegDecode BaseUsbHost FATFileSystem mbed-rtos mbed
bmp24.h
00001 #ifndef BMP24_H 00002 #define BMP24_H 00003 00004 #define BMP24_WIDTH (16*4) 00005 #define BMP24_HEIGHT (16*3) 00006 00007 class bmp24 { 00008 uint8_t m_bitmap[BMP24_WIDTH*BMP24_HEIGHT*3]; 00009 public: 00010 int width; 00011 int height; 00012 00013 bmp24() { 00014 width = BMP24_WIDTH; 00015 height = BMP24_HEIGHT; 00016 } 00017 00018 void clear() { 00019 memset(m_bitmap, 0, sizeof(m_bitmap)); 00020 } 00021 00022 void point(int x, int y, uint8_t* rgb) { 00023 if (x >= 0 && x < width && y >= 0 && y < height) { 00024 int pos = y*width*3+x*3; 00025 m_bitmap[pos++] = rgb[0]; 00026 m_bitmap[pos++] = rgb[1]; 00027 m_bitmap[pos] = rgb[2]; 00028 } 00029 } 00030 00031 void LE32write(uint8_t* buf, int value) { 00032 *buf++ = value & 0xff; 00033 *buf++ = (value>>8) & 0xff; 00034 *buf++ = (value>>16) & 0xff; 00035 *buf = (value>>24) & 0xff; 00036 } 00037 00038 bool writeFile(const char *path) { 00039 FILE *fp = fopen(path, "wb"); 00040 if (fp == NULL) { 00041 return false; 00042 } 00043 uint8_t header[] = { 00044 0x42,0x4d,0x36,0xe1,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00, 00045 0x00,0x00,0xa0,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00, 00046 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00047 0x00,0x00,0x00,0x00,0x00,0x00}; 00048 int file_size = sizeof(header) + sizeof(m_bitmap); 00049 LE32write(header+2, file_size); 00050 LE32write(header+18, width); 00051 LE32write(header+22, height); 00052 00053 fwrite(header, 1, sizeof(header), fp); 00054 for(int y = height-1; y >=0; y--) { 00055 for(int x = 0; x < width; x++) { 00056 fputc(m_bitmap[y*width*3+x*3+2], fp); 00057 fputc(m_bitmap[y*width*3+x*3+1], fp); 00058 fputc(m_bitmap[y*width*3+x*3+0], fp); 00059 } 00060 } 00061 fclose(fp); 00062 return true; 00063 } 00064 }; 00065 00066 #endif // BMP24_H
Generated on Tue Jul 12 2022 17:15:11 by
1.7.2