bmptoc.c
上传用户:qddsws
上传日期:2022-06-22
资源大小:723k
文件大小:1k
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #define byte unsigned char
- #define word unsigned short
- #define dword unsigned int
- struct BmpHeader {
- byte signature[2];
- byte size[4];
- byte reserved[2];
- byte reserved2[2];
- byte start_offset[4];
- byte bitmap_header_size[4];
- byte width[4];
- byte height[4];
- byte planes[2];
- byte bpp[2];
- byte compression[4];
- byte size_inclpad[4];
- byte hres[4];
- byte vres[4];
- byte ncolors[4];
- byte icolors[4];
- };
-
- int main (int argc, char *argv[]) {
- struct BmpHeader header;
-
- int width, height,start,bpp;
-
- printf ("static unsigned short logo_16bpp[] = { n");
- int in=open(argv[1],O_RDONLY);
- read(in,&header,sizeof(header));
- width=*(unsigned long*)header.width;
- height=*(unsigned long*)header.height;
- bpp=*(int*)header.bpp;
- bpp=bpp/8;
- start=*(unsigned long*)header.start_offset;
- unsigned long pixel;
- int i=0;
- printf ("%d,%d,",width,height);
- lseek (in,start,SEEK_SET);
- for (i=0;i<height*width*bpp;i=i+bpp) {
- read(in,&pixel,bpp);
- pixel=pixel&0x0000FFFF;
- pixel=( ((0x7C00&pixel)<<1) | (0x3E0&pixel)<<1 | ((0x1F&pixel)));
- printf ("0x%lx",(pixel&0x0000FFFF));
- if (i!=height*width*bpp-2) printf (",");
- if ((i+1)%15==0) printf ("n");
- }
- printf ("n};n");
- return 0;
- }