c语言bmp文件读取问题?
本人初学c语言,请教些问题?关于bmp文件读取的~#include <stdio.h>
#include <stdlib.h>
#pragma pack(1)
#include "bmp.h"
void bmp_read(char *file_name, COLOUR pixel[8][8])
{
BITMAPFILEHEADER bmp_fileheader;
BITMAPINFOHEADER bmp_infoheader;
RGBQUAD bmp_rgbquad[2];
unsigned char one_line;
int i,j;
FILE *f_bmp;
if ( (f_bmp = fopen(file_name, "rb")) == NULL)
{
printf("open bmp file: %s error\n", file_name);
exit(1);
}
if (fread(&bmp_fileheader, sizeof(BITMAPFILEHEADER), 1, f_bmp) != 1)
{
printf("read bmp file header error\n");
exit(1);
}
printf("bitmapfileheader = %d\n", sizeof(BITMAPFILEHEADER));
if (fread(&bmp_infoheader, sizeof(BITMAPINFOHEADER), 1, f_bmp) != 1)
{
printf("read bmp file information header error\n");
exit(1);
}
printf("bitmapinfoheader = %d\n", sizeof(BITMAPINFOHEADER));
if (fread(bmp_rgbquad, sizeof(RGBQUAD), 2, f_bmp) != 2)
{
printf("read bmp 调色板 error\n");
exit(1);
}
printf("index : red, green, blue \n");
for (i=0; i<2; i++)
printf("%d : %.2x %.2x %.2x\n", i, bmp_rgbquad[i].rgbBlue, bmp_rgbquad[i].rgbGreen, bmp_rgbquad[i].rgbRed);
for (i=0; i<bmp_infoheader.biHeight; i++)
{
if ( (fread(&one_line, sizeof(unsigned char), 1, f_bmp)) != 1)
{
printf("read one line error\n");
exit(1);
}
fseek(f_bmp, sizeof(unsigned char)*3, SEEK_CUR);
for (j=0; j<8; j++) //二值图像->24位真彩色
{
pixel[i][j].rgbRed = bmp_rgbquad[one_line].rgbRed;
pixel[i][j].rgbBlue = bmp_rgbquad[((one_line & 1<<(7-j))>>(7-j))].rgbBlue;//pixel[i][j].rgbRed;//((one_line & 1<<(7-j))>>(7-j)) * 255;
pixel[i][j].rgbGreen = bmp_rgbquad[((one_line & 1<<(7-j))>>(7-j))].rgbGreen;//pixel[i][j].rgbRed;//((one_line & 1<<(7-j))>>(7-j)) * 255;
}
}
fclose(f_bmp);
printf("\n");
}
其中one_line起什么作用?
//二值图像->24位真彩色这一段帮忙解释一下?
当然如果能整段程序一起解释那最好了~