📄 bmp2rgb.c
字号:
#include <stdio.h>struct __attribute__((packed)) fh{unsigned short int bfType;unsigned int bfSize;unsigned short int Res1;unsigned short int Res2;unsigned int bfOffBits;unsigned int biSize;unsigned int biWidth;unsigned int biHeight;unsigned short int biPlanes;unsigned short int biBitCount;unsigned int biCompression;unsigned int biSizeImage;unsigned int biXPelsPerMeter;unsigned int biYPelsPerMeter;unsigned int biClrUsed;unsigned int biClrImportant;};main (int argc, char **argv){ static struct fh file_header, *fhp; FILE *fpr, *fpw; unsigned char colortable[0xff]; unsigned char entry[0x04]; unsigned char byte, colors; int i; fhp = &file_header; if (((fpr = fopen(argv[1], "r")) == NULL) || ((fpw = fopen(argv[2], "w")) == NULL)) printf("Usage: bmp2rgb <bmpfile> <rgbfile>\n"); else { byte = fread((char *) &file_header, sizeof(file_header), 1, fpr); printf("Bytes read: %d.\n", byte); printf("Image size: %d x %d.\n", file_header.biWidth, file_header.biHeight); fseek(fpr, 0x36, 0); // jump to color table if (file_header.biClrUsed == 0) colors = 0xff; else colors = file_header.biClrUsed; printf("Number of used colors: %d\n", colors); for (i=0; i<colors;i++) { fread(entry, 4, 1, fpr); colortable[i] = (entry[2] & 0xe0) | ((entry[1] & 0xe0) >> 3) | ((entry[0] & 0xe0) >> 6);// printf("%2x, %2x, %2x --> %2x\n", entry[0], entry[1], entry[2], colortable[i]); } fseek(fpr, file_header.bfOffBits, 0); // jump to data area while (fread(&byte, 1, 1, fpr)) {// printf("%2x,", byte); fputc(colortable[byte], fpw); } fclose(fpr); fclose(fpw); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -