[请教]tc 320X200 X256色模式下bmp图片显色与原图颜色不符!
下面这个是我根据网上bmp的格式,在win-tc下写的bmp图片显示程序,程序输出的图片和原图片颜色严重不同,我怀疑是调色板寄存器方面的设置不当,但是又不知道怎么处理,网上也查过相关资料,还是搞不定!望达人来助!小生在这有礼了!
320X200X256色图片可以用绘图板做一个,名称为256.bmp,和源文件在同一个目录下就可以了,我没有写检测256bmp的代码!
#include<io.h>
#include<stdio.h>
#include<dos.h>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<bios.h>
#include<mem.h>
#include<fcntl.h>
#include<stdlib.h>
#include<conio.h>
#define RED 0
#define GREEN 1
#define BLUE 2
#define SCREEN_HEIGHT 200
#define SCREEN_WIDTH 320
#define PALETTE_MASK 0x3c6
#define PALETTE_REGISTER_RD 0x3c7
#define PALETTE_REGISTER_WR 0x3c8
#define PALETTE_DATA 0x3c9
#define VGA256 0x13
#define TEXT_MODE 0x03
unsigned char far *video_buffer=(char far *)0xa0000000L;
/* bmp图片格式 */
/*
typedef struct BMP_file
{
unsigned int bfType;
unsigned long bfSize;
unsigned int Reserved1;
unsigned int reserved2;
unsigned long bfOffset;
}
bitmapfile;
typedef struct BMP_info
{
unsigned long biSize;
unsigned long biWidth;
unsigned long biHeight;
unsigned int biPlanes;
unsigned int biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
unsigned long biXpolsPerMeter;
unsigned long biYpelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
}
bitmapinfo;
typedef struct RGB_BMP_typ
{
unsigned char blue;
unsigned char green;
unsigned char red;
unsigned char reserved;
}RGB_BMP,*RGB_BMP_ptr;
typedef struct bmp_picture_typ
{
bitmapfile file;
bitmapinfo info;
RGB_BMP palette[256];
char far *buffer;
} bmp_picture, *bmp_picture_ptr;
*/
/*
void Set_BMP_Palette_Register(int index,RGB_BMP_ptr color)
{
outp(PALETTE_MASK,0xff);
outp(PALETTE_REGISTER_WR,index);
outp(PALETTE_DATA,color->red);
outp(PALETTE_DATA,color->green);
outp(PALETTE_DATA,color->blue);
}
*/
void BMP_Load_Screen(char *bmp)
{
int i,j;
unsigned int k=0;
unsigned char *p=NULL;
FILE *fp;
char b[4];
if ((fp=fopen(bmp,"r"))==NULL)
{
printf("can't open!") ;
getch();
exit(0);
}
for (i=0;i<256;i++) /*读取bmp颜色到调色板寄存器*/
{
fread(&b[BLUE],1,1,fp);
fread(&b[GREEN],1,1,fp);
fread(&b[RED],1,1,fp);
fread(&b[3],1,1,fp);
b[RED]=b[RED]>>2;
b[GREEN]=b[GREEN]>>2;
b[BLUE]=b[BLUE]>>2;
outp(PALETTE_MASK,0xff);
outp(PALETTE_REGISTER_WR,i);
outp(PALETTE_DATA,b[RED]);
outp(PALETTE_DATA,b[GREEN]);
outp(PALETTE_DATA,b[BLUE]);
}
for(i=SCREEN_HEIGHT-1;i>=0;i--) /*读取bmp颜色到显存*/
{
fseek(fp,1078+(unsigned)i*SCREEN_WIDTH,SEEK_SET);
for(j=0;j<SCREEN_WIDTH;j++)
{
fread(p,1,1,fp);
video_buffer[k++]= *p;
}
}
fclose(fp);
}
void Set_Video_Mode(int mode) /*设置视频模式320X200X256色*/
{
union REGS inregs,outregs;
inregs.h.ah=0;
inregs.h.al=(unsigned char)mode;
int86(0x10,&inregs,&outregs);
}
int main()
{
Set_Video_Mode(VGA256);
BMP_Load_Screen("256.bmp");
getch();
Set_Video_Mode(TEXT_MODE);
}
[[it] 本帖最后由 yaonai2003 于 2008-4-25 12:14 编辑 [/it]]