CQ出版 Interface記事用サンプル。 トラ技カメラ+FIFOからデータを得て、 エリア判定後、デバイスに保存
Dependencies: SDFileSystem mbed
Revision 4:ed062dc75c52, committed 2014-02-04
- Comitter:
- TETSUYA
- Date:
- Tue Feb 04 05:42:17 2014 +0000
- Parent:
- 3:8d5594ce5b00
- Commit message:
- ???????
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8d5594ce5b00 -r ed062dc75c52 main.cpp --- a/main.cpp Tue Oct 01 01:55:39 2013 +0000 +++ b/main.cpp Tue Feb 04 05:42:17 2014 +0000 @@ -27,6 +27,9 @@ # define SIZEY (240) #endif +#define COLORS 8 // 8bit colors +//#define COLORS 24 // 24bit colors + int create_header(FILE *fp, int width, int height) ; #define FILEHEADERSIZE 14 //ファイルヘッダのサイズ @@ -66,7 +69,7 @@ int face_bank = 0; int Dbmode = 0; void MedianFilter(void); -void SaveBMP(void); +void SaveBMP(int flag); void SearchNewFileNo(); @@ -74,16 +77,17 @@ char color_format = 0; char c; int d1,d2 ; - int mx, pixel , i; + //int mx, pixel , i; + int pixel ; int pixc, pixelg; int sort[3]; int ay = 0; - char UseMedian = 0; + //char UseMedian = 0; memset( AreaDiff, '\0', sizeof(AreaDiff)); pc.baud(115200); -RESJMP: +//RESJMP: //pc.printf("Camera resetting..\r\n"); camera.Reset(); @@ -118,23 +122,26 @@ { memset( &AreaDiff[face_bank], '\0', sizeof(AreaDiff[face_bank])); if ( Dbmode ){ - pc.printf("Hit Any Key to send RGBx160x120 Capture Data.\r\n") ; + pc.printf("Debug Mode [d][s] Any Charactor is Capture Start! \r\n") ; while(!pc.readable()) ; c = pc.getc() ; + /* if (( c == '1' )|| ( c == '2' )||( c == '3' )){ color_format = c; goto RESJMP; - }else if (( c == 'd' )|| ( c == 'D' )){ - Dbmode = 0; // GO FreeRun - continue; }else if ( ( c== 'm')||( c== 'M')) { UseMedian = 1; continue; }else if ( ( c== 'n')||( c== 'N')) { UseMedian = 0; continue; + }else + */ + if (( c == 'd' )|| ( c == 'D' )){ + Dbmode = 0; // GO FreeRun + continue; }else if ( ( c== 's')||( c== 'S')) { - SaveBMP(); + SaveBMP(COLORS); continue; } }else{ @@ -143,13 +150,16 @@ if (( c == 'd' )|| ( c == 'D' )){ Dbmode = 1; // GO DEBUGmode continue; - }else if ( ( c== 'm')||( c== 'M')) { + } + /* + else if ( ( c== 'm')||( c== 'M')) { UseMedian = 1; continue; }else if ( ( c== 'n')||( c== 'N')) { UseMedian = 0; continue; } + */ } pc.printf(" \r\n") ; } @@ -183,7 +193,6 @@ canvas[x][y] = (char)( gray ) & 0x3f; // 6bit gray scale // Make Difference AreaData - //AreaDiff[face_bank][x/AREA_X][ay] += ( gray << 2 ); // 8bit scaler! AreaDiff[face_bank][x/AREA_X][ay] += ( gray ); // 6bit scaler! if ( Dbmode ){ @@ -267,7 +276,7 @@ } } } - SaveBMP(); + SaveBMP(COLORS); } face_bank++; @@ -314,8 +323,8 @@ } } -//char *filebase = "/local/Bmap"; -char *filebase = "/sd/Bmap"; +char *filebase = "/local/Bmap"; +//char *filebase = "/sd/Bmap"; void SearchNewFileNo() { @@ -337,14 +346,16 @@ } -void SaveBMP(void) +//flag 24: 24bit Clolr 8:8itGrayScale +void SaveBMP(int flag) { unsigned char gray8; unsigned char bmp_line_data[SIZEX*3]; //画像1行分のRGB情報を格納する + unsigned char RGBQUAD[4]; //Palette Data int back ; FILE *fp; char filename[30] ; - + sprintf( filename, "%s%04d.bmp", filebase , FileNo); FileNo++; back = myleds; @@ -358,16 +369,35 @@ // Make BITMAPHEADER to FileHead. create_header(fp, SIZEX, SIZEY); + if ( flag==8 ){ + // if 8bit Gray Scale , Make Palette Data + for (int i=0;i<256;i++){ + RGBQUAD[0] = i; // + RGBQUAD[1] = i; + RGBQUAD[2] = i; + RGBQUAD[3] = 0; + fwrite(RGBQUAD, sizeof(RGBQUAD), 1, fp); + } + } + for (int y=0; y<SIZEY; y++) { - for (int x=0; x<SIZEX; x++) { - // RGB888 - gray8 = (unsigned char)(canvas[x][y] << 2); //grayscale data 6bit - - bmp_line_data[x*3] = (unsigned char)gray8; // b - bmp_line_data[x*3 + 1] = (unsigned char)gray8; // g - bmp_line_data[x*3 + 2] = (unsigned char)gray8; // r + if ( flag==24 ){ + for (int x=0; x<SIZEX; x++) { + // RGB888 + gray8 = (unsigned char)(canvas[x][y] << 2); //grayscale data 6bit + + bmp_line_data[x*3] = (unsigned char)gray8; // b + bmp_line_data[x*3 + 1] = (unsigned char)gray8; // g + bmp_line_data[x*3 + 2] = (unsigned char)gray8; // r + } + fwrite(bmp_line_data, sizeof(unsigned char), sizeof(bmp_line_data), fp); + }else{ + // GrayScale + for (int x=0; x<SIZEX; x++) { + gray8 = (unsigned char)(canvas[x][y] << 2); //grayscale data 6bit + fwrite(&gray8 , 1, 1, fp); + } } - fwrite(bmp_line_data, sizeof(unsigned char), sizeof(bmp_line_data), fp); } fclose(fp); @@ -392,10 +422,15 @@ //ここからヘッダ作成 file_size = height * real_width + HEADERSIZE; + offset_to_data = HEADERSIZE; + if ( COLORS == 8 ) { + offset_to_data += 256 * 4; + } + info_header_size = INFOHEADERSIZE; planes = 1; - color = 24; + color = COLORS; // 24; compress = 0; data_size = height * real_width; xppm = 1; @@ -419,11 +454,11 @@ memcpy(header_buf + 34, &data_size, sizeof(data_size)); memcpy(header_buf + 38, &xppm, sizeof(xppm)); memcpy(header_buf + 42, &yppm, sizeof(yppm)); - header_buf[46] = 0; + header_buf[46] = 0; // Palette Color (long) header_buf[47] = 0; header_buf[48] = 0; header_buf[49] = 0; - header_buf[50] = 0; + header_buf[50] = 0; // Important Color (long) header_buf[51] = 0; header_buf[52] = 0; header_buf[53] = 0;