Any changes are to allow conversion to BMP

Dependencies:   BaseJpegDecode Camera_LS_Y201 Motordriver Servo mbed

Fork of Bitmap_copy_copy by Eric Wieser

Committer:
kylepost3
Date:
Wed Apr 30 14:19:33 2014 +0000
Revision:
1:d721e32cf79c
Final design project for ECE 4180.  The device takes scans left to right taking pictures (In JPEG), converts the picture to BMP, and scans for red pixels.  When the threshold of red pixels is reached, it fires the catapult and reloads.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kylepost3 1:d721e32cf79c 1 #ifndef BMP24_H
kylepost3 1:d721e32cf79c 2 #define BMP24_H
kylepost3 1:d721e32cf79c 3
kylepost3 1:d721e32cf79c 4 #define BMP24_WIDTH (80) //(16*4)
kylepost3 1:d721e32cf79c 5 #define BMP24_HEIGHT (60) //(16*3)
kylepost3 1:d721e32cf79c 6
kylepost3 1:d721e32cf79c 7 class bmp24 {
kylepost3 1:d721e32cf79c 8 uint8_t m_bitmap[BMP24_WIDTH*BMP24_HEIGHT*3];
kylepost3 1:d721e32cf79c 9 public:
kylepost3 1:d721e32cf79c 10 int width;
kylepost3 1:d721e32cf79c 11 int height;
kylepost3 1:d721e32cf79c 12
kylepost3 1:d721e32cf79c 13 bmp24() {
kylepost3 1:d721e32cf79c 14 width = BMP24_WIDTH;
kylepost3 1:d721e32cf79c 15 height = BMP24_HEIGHT;
kylepost3 1:d721e32cf79c 16 }
kylepost3 1:d721e32cf79c 17
kylepost3 1:d721e32cf79c 18 void clear() {
kylepost3 1:d721e32cf79c 19 memset(m_bitmap, 0, sizeof(m_bitmap));
kylepost3 1:d721e32cf79c 20 }
kylepost3 1:d721e32cf79c 21
kylepost3 1:d721e32cf79c 22 void point(int x, int y, uint8_t* rgb) {
kylepost3 1:d721e32cf79c 23 if (x >= 0 && x < width && y >= 0 && y < height) {
kylepost3 1:d721e32cf79c 24 int pos = y*width*3+x*3;
kylepost3 1:d721e32cf79c 25 m_bitmap[pos++] = rgb[0];
kylepost3 1:d721e32cf79c 26 m_bitmap[pos++] = rgb[1];
kylepost3 1:d721e32cf79c 27 m_bitmap[pos] = rgb[2];
kylepost3 1:d721e32cf79c 28 }
kylepost3 1:d721e32cf79c 29 }
kylepost3 1:d721e32cf79c 30
kylepost3 1:d721e32cf79c 31 void LE32write(uint8_t* buf, int value) {
kylepost3 1:d721e32cf79c 32 *buf++ = value & 0xff;
kylepost3 1:d721e32cf79c 33 *buf++ = (value>>8) & 0xff;
kylepost3 1:d721e32cf79c 34 *buf++ = (value>>16) & 0xff;
kylepost3 1:d721e32cf79c 35 *buf = (value>>24) & 0xff;
kylepost3 1:d721e32cf79c 36 }
kylepost3 1:d721e32cf79c 37
kylepost3 1:d721e32cf79c 38 bool writeFile(const char *path) {
kylepost3 1:d721e32cf79c 39 FILE *fp = fopen(path, "wb");
kylepost3 1:d721e32cf79c 40 if (fp == NULL) {
kylepost3 1:d721e32cf79c 41 return false;
kylepost3 1:d721e32cf79c 42 }
kylepost3 1:d721e32cf79c 43 uint8_t header[] = {
kylepost3 1:d721e32cf79c 44 0x42,0x4d,0x36,0xe1,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
kylepost3 1:d721e32cf79c 45 0x00,0x00,0xa0,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
kylepost3 1:d721e32cf79c 46 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
kylepost3 1:d721e32cf79c 47 0x00,0x00,0x00,0x00,0x00,0x00};
kylepost3 1:d721e32cf79c 48 int file_size = sizeof(header) + sizeof(m_bitmap);
kylepost3 1:d721e32cf79c 49 LE32write(header+2, file_size);
kylepost3 1:d721e32cf79c 50 LE32write(header+18, width);
kylepost3 1:d721e32cf79c 51 LE32write(header+22, height);
kylepost3 1:d721e32cf79c 52
kylepost3 1:d721e32cf79c 53 fwrite(header, 1, sizeof(header), fp);
kylepost3 1:d721e32cf79c 54 for(int y = height-1; y >=0; y--) {
kylepost3 1:d721e32cf79c 55 for(int x = 0; x < width; x++) {
kylepost3 1:d721e32cf79c 56 fputc(m_bitmap[y*width*3+x*3+2], fp);
kylepost3 1:d721e32cf79c 57 fputc(m_bitmap[y*width*3+x*3+1], fp);
kylepost3 1:d721e32cf79c 58 fputc(m_bitmap[y*width*3+x*3+0], fp);
kylepost3 1:d721e32cf79c 59 }
kylepost3 1:d721e32cf79c 60 }
kylepost3 1:d721e32cf79c 61 fclose(fp);
kylepost3 1:d721e32cf79c 62 return true;
kylepost3 1:d721e32cf79c 63 }
kylepost3 1:d721e32cf79c 64 };
kylepost3 1:d721e32cf79c 65
kylepost3 1:d721e32cf79c 66 #endif // BMP24_H