我依照NEO的子程序,可是24K的BMP图片显示不出来,请指点?
#define SRGB332(r, g, b) ((((r) / 9) << 5) + (((g) / 9)<<2) + (b) / 21)
void _Cdecl Show_BMP(char *File_Name, int x, int y)
{
int i, j, width, color,len;
FILE *fp;
unsigned char *buffer;
RGB24 *RGB_buffer;
RGBQUAD *RGB;
BITMAPFILEHEADER *FileHead;
BITMAPINFOHEADER *InfoHead;
if ((fp=fopen(File_Name,"rb")) == NULL)
{
printf("BMP File not exist ...");
return;
}
RGB = (RGBQUAD *)malloc(sizeof(RGBQUAD));
FileHead = (BITMAPFILEHEADER *)malloc(sizeof(BITMAPFILEHEADER));
InfoHead = (BITMAPINFOHEADER*)malloc(sizeof(BITMAPINFOHEADER));
fread(FileHead,sizeof(BITMAPFILEHEADER),1,fp);
if (FileHead->bfType!='BM')
{
printf("BMP File type Error ...");
return;
}
fread(InfoHead,sizeof(BITMAPINFOHEADER),1,fp);
if (InfoHead->biCompression !=0 || (InfoHead->biBitCount!=8 && InfoHead->biBitCount!=24))
{
printf("BMP File not Support Compression type ...");
fclose(fp);
return;
}
width =((int)InfoHead->biWidth+3)/4*4; // 每行字节数--4的整数倍
if ((buffer = (unsigned char *)malloc(width)) == NULL) // 申请缓冲区
{
fclose(fp);
return;
}
if ((int)InfoHead->biBitCount == 8) // 色深=8
{
for (i = 0 ; i < 256 ; i++)
{
fread(RGB,sizeof(RGBQUAD),1,fp);
outportb(0x3C8,i);
outportb(0x3C9,RGB->rgbRed>>2);
outportb(0x3C9,RGB->rgbGreen>>2);
outportb(0x3C9,RGB->rgbBlue>>2);
}
for (j = (int)InfoHead->biHeight-1 ; j >= 0 ; j--)
{
fread(buffer,width,sizeof(unsigned char),fp);
for (i = 0; i < width; i++)
PutPixel(i+x,j+y,buffer[i]);
}
}
else if ((int)InfoHead->biBitCount == 24) // 色深=24
{
len=(int)InfoHead->biWidth*sizeof(RGB24)+(int)InfoHead->biWidth&3;
if ((RGB_buffer = (RGB24 *)malloc(len)) == NULL)
{
fclose(fp);
return;
}
for (j = (int)InfoHead->biHeight-1 ; j >= 0 ; j--)
{
fread(RGB_buffer,len,sizeof(char),fp); /*读取该行像素的所有点的颜色*/
for (i=0;i<len;i++)
{
color = SRGB332(RGB_buffer[i].r,RGB_buffer[i].g,RGB_buffer[i].b);
PutPixel(i+x,j+y,color);
}
}
}
free(FileHead);
free(InfoHead);
free(RGB);
}