📄 catch.c
字号:
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <string.h>#include <unistd.h>#define SCREEN_WIDTH 640 /* default width */#define SCREEN_HEIGHT 480 /* default height */#define BmpDirectory "/buffer/test/"unsigned char RGBbuffer[SCREEN_WIDTH*SCREEN_HEIGHT*2];unsigned char Filebuffer[SCREEN_WIDTH*SCREEN_HEIGHT*2];#pragma pack(1)struct BmpFileHead{ unsigned short FileFlag; unsigned long FileSize; unsigned long Reserve; unsigned long Bmp_Offset; unsigned long Bit_Head_Info; unsigned long Width; unsigned long Height; unsigned short Planes; unsigned short Bit_Pixel; unsigned long Compression; unsigned long Bit_Size; unsigned long HResolution; unsigned long VResolution; unsigned long Colors; unsigned long Important_Colors; } ;struct colortable{ unsigned long red; unsigned long green; unsigned long blue;};struct colortable color16table;struct BmpFileHead bmp16head;int main (int argc, char *argv[]){ int sreenfp; unsigned char *RGBbfpt; FILE *bmpfp; char bmpfile[50]; char filename[10]; int row,col,input,fileno; bmp16head.FileFlag = 0x4d42; bmp16head.FileSize = 0x000e1036; bmp16head.Reserve = 0x00000000; bmp16head.Bmp_Offset = 0x00000042; bmp16head.Bit_Head_Info = 0x00000028; bmp16head.Width = 0x00000280; bmp16head.Height = 0x000001e0; bmp16head.Planes = 0x0001; bmp16head.Bit_Pixel = 0x0010; bmp16head.Compression = 0x00000003; bmp16head.Bit_Size = 0x00000000; bmp16head.HResolution = 0x00000000; bmp16head.VResolution = 0x00000000; bmp16head.Colors = 0x00000000; bmp16head.Important_Colors = 0x00000000; color16table.red = 0x0000f800; color16table.green = 0x000007e0; color16table.blue = 0x0000001f; fileno = 0; if(!access(BmpDirectory,F_OK)) { printf("welcome use catch.\n"); printf("please press enter to catch *.bmp,this file is saved /buffer/test directory.\n"); printf("you can press q to quit.\n"); printf("please press enter to continue.\n"); } else { printf("please sure /buffer/test exist.\n"); return 0; } while(1) { input = getchar(); if(input==10) { if((sreenfp=open("/dev/fb0",O_RDONLY))<0) { printf(" open /dev/fb0 is failed\n"); exit(0); } RGBbfpt = RGBbuffer; read(sreenfp, RGBbfpt, SCREEN_WIDTH*SCREEN_HEIGHT*2); close(sreenfp); for(row=0;row<480;row++) { for(col=0;col<640;col++) { Filebuffer[(row*640+col)*2] = RGBbuffer[((479-row)*640+col)*2]; Filebuffer[(row*640+col)*2+1] = RGBbuffer[((479-row)*640+col)*2+1]; } } fileno++; sprintf(filename,"%04d",fileno); strcpy(bmpfile,BmpDirectory); strcat(bmpfile,filename); strcat(bmpfile,".bmp"); if((bmpfp=fopen(bmpfile,"wb+"))==NULL) { printf("can not creat a new file.\n"); exit(0); } printf("current file is %s\n",bmpfile); if(fwrite(&bmp16head, sizeof(struct BmpFileHead), 1, bmpfp)!=1) { printf("file write failed\n"); return 1; } fclose(bmpfp); if((bmpfp=fopen(bmpfile,"ab"))==NULL) { printf("can not creat a new file.\n"); exit(0); } if(fwrite(&color16table, sizeof(struct colortable), 1, bmpfp)!=1) { printf("file write failed\n"); return 1; } fclose(bmpfp); if((bmpfp=fopen(bmpfile,"ab"))==NULL) { printf("can not open %s.\n",bmpfile); exit(0); } if(fwrite(Filebuffer, 1, SCREEN_WIDTH*SCREEN_HEIGHT*2, bmpfp)!=SCREEN_WIDTH*SCREEN_HEIGHT*2) { printf("file write failed\n"); return 1; } fclose(bmpfp); printf("please press enter continue.\n"); } else { if(input==113) break; } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -