关于GIF颜色表及解码的问题
#include <conio.h>
#include <stdlib.h>
#include <alloc.h>
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
#include <fcntl.h>
#include <string.h>
#include <process.h>
#include <bios.h>
#include "gif89.c"
unsigned int lowidth,lohigth;
char page_new=0,page_old=0;
void selectpage(register char page)
{ union REGS r;
r.x.ax=0x4f05;
r.x.bx=0;
r.x.dx=page;
int86(0x10,&r,&r);
}
unsigned char set_SVGA_mode(int vmode)
{
union REGS r;
r.x.ax=0x4f02;
r.x.bx=vmode;
int86(0x10,&r,&r);
return(r.h.ah);
}
unsigned int get_SVGA_mode()
{ union REGS r;
r.x.ax=0x4f03;
int86(0x10,&r,&r);
return(r.x.bx);
}
void PutPoint(int x, int y, char Color)
{
long position;
position=y*640l+x;
page_new=position/65536l;
if(page_new!=page_old)
selectpage(page_new);
pokeb(0xa000,position%65536l,Color);
}
void Out_Line(char *ptr, int x, int y,int width)
{
int i;
for(i=0; i<width; i++)
{
PutPoint(x++,y,ptr[i]);
}
}
void disp(unsigned char *image,unsigned char *pattern,unsigned int width,unsigned int higth)
{
int i,j,k,max,may;
char* buffer;
char* mage;
/* write to display card*/
buffer = (char*)malloc(width);
mage = (unsigned char*)malloc(width*higth);
for(i=0; i<higth*width; i++)
{
mage[i] = pattern[image[i]];
}
k=(width%4)?(4-width%4):0;
max=(640+width)/2-width;
may=(480-higth)/2+higth;
for(j=0;j<higth;j++)
{
fread(buffer,width,1,mage);
Out_Line(buffer,max,may-j,width);
fseek(mage,k,1);
}
}
void main(int argc,char *argv[])
{
unsigned char pat[256][3];
int bit_count,savemode;
unsigned int j;
long i;
unsigned int frames;
FRAME* fm;
char* all;
unsigned int grwidth,grhigth;
unsigned int delayTime;
GLOBAL_INFO* gi;
char* File = "C:\\ibm1.gif";
unsigned int seg = 0;
if(CGif89a(File,seg)==1)
{
printf("open error!");
exit(1);
}
savemode=get_SVGA_mode();
set_SVGA_mode(0x101);
gi = getGlobalInfo();
lowidth = gi->scrWidth;
lohigth = gi->scrHeight;
frames = gi->frames;
if(frames=1)
{
fm==NULL;
fm = getNextFrame();
if(fm == NULL)
{
printf("NO more frame!");
return;
}
grwidth= fm->imageWidth;
grhigth= fm->imageHeight;
if(fm->lFlag==1)
{
disp(fm->dataBuf,fm->pColorTable,grwidth,grhigth);
}
else
{
disp(fm->dataBuf,gi->gColorTable,grwidth,grhigth);
}
getchar();
}
else
{
while(1)
{
j=0;
for(;j<frames;j++)
{
memset(MK_FP(0xa000,0),0,lowidth*lohigth);
fm==NULL;
fm = getNextFrame();
if(fm == NULL)
{
printf("NO more frame!");
return;
}
grwidth= fm->imageWidth;
grhigth= fm->imageHeight;
if(fm->lFlag==1)
{
disp(fm->dataBuf,fm->pColorTable,grwidth,grhigth);
}
else
{
disp(fm->dataBuf,gi->gColorTable,grwidth,grhigth);
}
sleep(fm->ctrlExt.delayTime*100);
}
}
}
getchar();
free(gi);
free(fm);
fclose(File);
bioskey(0);
set_SVGA_mode(savemode);
}
小弟最近需要写一个能在TC中显示GIF动画的程序,是用GIF89A做为解码来做的
但是一直不能正确显示GIF图片(不管是一帧还是多帧),怀疑是颜色表索引的问题
而且图象也不能正确显示,估计是解码的问题。还有如何显示透明色也不太明白。希望各位高手能帮帮
小弟,不甚感激,谢谢