在TVGA上实现全屏幕动画

时间:2020-08-25 15:01:14 计算机毕业论文 我要投稿

在TVGA上实现全屏幕动画


   在图像处理领域,当处理或分析序列运动图像时,需要在屏幕上连续显示这一序列图像(即动画播放),以便观察处理效果或分析动态信息。一般游戏动画的设计方法是慢速移动背景和快速刷新运动目标(小画面),难以实现全屏动画效果。为此笔者采用了汇编语言编程和快速写屏的方法,在普通的486微机(主频66M,配TVGA9000卡)上达到了每秒显示10幅640×480×256灰阶图像的速度,效果令人满意。
首先设置TVGA卡使其工作在0X5d方式下,屏幕分辨率是640×480×256色。然后重新构造调色板(RemapPalette()),使其适于显示256灰阶的图像。由于TVGA卡的颜色寄存器使用18位存储模式,即R、G、B分量各占6位,而要显示灰度图像R、G、B分量必须赋予相同的值,所以就只能显示区分26=64灰阶的'图像。不过,实验表明人眼已无法区分64灰阶与256灰阶图像的差别。因此,在构造调色板时,0~3索引值对应的R、G、B分量值都为0,4~7索引值对应的R、G、B分量值都为1,…,依次类推,这样就可以正确显示一幅256灰阶的图像。
以下是动画播放序列运动图像完整的源代码(AVD.C)。为连续显示一序列图像,先将序列图像的数目(如20)、存放图像数据文件的路径(f:\zyf\)、图像文件的名称(如z1.img,z2.img,…)录入一文本文件(如imggroup.lst),运行程序时只需键入AVD imggroup.lst即可。源程序中显示每幅图像的代码部分采用嵌入汇编语言编写,以得到较高的显示速度。在程序运行过程中,按下空格键暂停;连击空格键实现单帧播放;按下任意其它键恢复连续播放;按下退出键(Escape)退回DOS。在程序设计时,为避免在一个循环结束过渡到下一个循环开始时将要从序列的最后一幅图像切换到第一幅图像,因为这时由于图像运动的不连续性将产生突变,以至屏幕显示有抖动感或闪烁感,所以笔者采用了第一个循环正向播放,第二个循环反向播放(即正反相间)的方案。如果读者只希望正向播放,只须删除源程序中标有“//$$$”的四条语句行即可。
编译运行环境:本程序用MS C6.0编译通过,编译时请使用命令行参数/STACK:20480;图像数据文件来自大恒公司的VP32图像采集板(512×512×256灰阶)。
#include <graph.h>
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#define IMGGRP 30 //Image Number in a Cycle Showing
#define ESCAPE 27 //Stop Showing and Exit
#define SPACE 32 //Step Show--Hit Space Bar & One by One Showing
void RemapPalette(void);
void main (int argc,char *argv[])
{
static char grpflnm[IMGGRP][80];
char path[80],flnm[80],bindfn[80],arg[5];
char fnch[2]="\0";
char ch-imgnum[5];
int i,i1,i2,i12,ii,imgnum=IMGGRP;
int dispimgs,keyin,StepShow=0;
unsigned short int VSEG;
union REGS inregs,outregs;
FILE *fp;
unsigned short int row=480,col=512;
unsigned char fb[512];
int m-b=0;
clock-t cstart,cend; /* For clock */
unsigned short int FH; // File Handle
printf("\n ********** GROUP IMAGES ANIMATEDLY SHOWING ********* \n");
if(argc>1)
strcpy(flnm,argv[1]);
else
{
printf("\n Input the Image Group file name [.lst]:");
gets(flnm);
}
REDISP:
if(!strchr(flnm,'.'))
strcat(flnm,".lst");
if((fp=fopen(flnm,"rt"))==NULL)
{
printf("\n Open file failure!! \a\a\n");
printf("\n Please Check following files whether exist:");
printf("\n%s",flnm);
printf("\n\n Note:The file extension name is appended automatically,");
printf("\n such as [.lst]!");
exit(1);
}
inregs.x.ax=0x005d; // Set TVGA Mode:640x480x256 levels
int86(0x10,&inregs,&outregs);
RemapPalette(); // Remap all Palette
cstart= clock(); /* Use clock for timing to hundredths of seconds */
strcpy(ch-imgnum,"\0");
for(;;) // Read image number in group
{
fread(fnch,sizeof(char),1,fp);
if((int)fnch[0]==10) break;
strcat(ch-imgnum,fnch);
}
imgnum=atoi(ch-imgnum);
strcpy(path,"\0");
for(;;) // Read image path in group
{
fread(fnch,sizeof(char),1,fp);
if((int)fnch[0]==10) break;
strcat(path,fnch);
}
for(i=0;i<imgnum;i++) // Read image name in group
{
strcpy(grpflnm[i],"\0");
for(;;)
{
fread(fnch,sizeof(char),1,fp);
if((int)fnch[0]==10) break;
strcat (grpflnm[i],fnch);
}
}
keyin=0;
StepShow=0; // Continuous Showing defaultly
dispimgs=0;
i1=0; i2=imgnum-1; i12=1;
for(;;) // SHOW IMAGES--ANTMATE PICTURE [STUDIO]
{// REPEAT CYCLE FOREVER
for(i=i1;i<=i2;i+=i12)
{
if(kbhit())
{
keyin=getch();
if(keyin==ESCAPE) goto CONTINUE; //Stop Showing and Exit
if(keyin==SPACE) StepShow=1; // Step Show--Hit Sapce Bar
else StepShow=0; // Continuous Showing--Hit Any Other Key
}
if(StepShow==1)
{
keyin=getch(); //Standy by
if(keyin==ESCAPE) goto CONTINUE;
if(keyin!=SPACE) StepShow=0;
}
strcpy(bindfn,path);
strcat(bindfn,grpflnm[i]);
strcpy(flnm,bindfn);
VSEG=0;
-asm
{
MOV AH,3dh ;Open File
MOV AL,0c0h
LEA DX,WORD PTR flnm
INT 21h
MOV FH, AX
MOV AX,0a000h
MOV ES,AX
XOR DI,DI
MOV AX,0eh
MOV DX,3c4h
OUT DX,AL
XOR AX,AX
XOR AX,02h
MOV DX,3c5h
OUT DX,AL
MOV CX,row
OUTER-CYCLE:
PUSH CX
MOV AH,3fh ;Read File a Line Once
MOV BX,FH
MOV CX,col ;col=512
LEA DX,WORD PTR fb
INT 21h
MOV SI,DX
MOV CX,col
INTER-CYCLE:
MOVSB
OR DI,DI
JNZ GO-INTER-LOOP
MOV AX,0eh
MOV DX,3c4h
OUT DX,AL
MOV AX,VSEG
INC AX
MOV VSEG,AX
XOR AX, 02h
MOV DX,3c5h
OUT DX,AL
GO-INTER-LOOP:
LOOP INTER-CYCLE
ADD DI,128 ;128=640-512
JNC GO-OUTER-LOOP
MOV AX,0eh
MOV DX,3c4h
OUT DX,AL
MOV AX,VSEG
INC AX
MOV VSEG,AX
XOR AX,02h
MOV DX,3c5h
OUT DX,AL
GO-OUTER-LOOP:
POP CX
LOOP OUTER-CYCLE
MOV AH,3eh ;Close File
MOV BX,FH
INT 21h
}
dispimgs++;
}
/* The following line (4 sentences) can be Deleted if wish Up-showing On
ly
*/
ii=i1; i1=i2; i2=ii; i12*=(-1); //$$$
}
CONTINUE:
cend=clock();
printf("\a");
getch();
fclose(fp);
if(argc>1) goto ENDP;
printf("\n Display Another Image Group(Y/[N])?");
gets(arg);
if(!strcmp(arg,"Y")||!strcmp(arg,"y"))
{
printf("\n Input image file name:");
gets(flnm);
goto REDISP;
}
ENDP:
-SETVIDEOMODE(-TEXTC80);
printf(" Show %5d images;Spend %4.2f seconds.\n",dispimgs,((float)cend-cst
art)
/CLK-TCK);
}
void RemapPalette(void)
{
register int i,j;
union REGS inregs,outregs;
for(j=0;j<64;i++) //Remap TVGA Palette
for(i=0;i<4;j++)
{
inregs.x.ax=0x1010;
inregs.x.bx=(unsigned char)(4*i+j); //Index value
inregs.h.ch=(unsigned char)i; //Green value R,G,B=0-63
inregs.h.cl=(unsigned char)i; //Blue value
inregs.h.dh=(unsigned char)i;
//Red value
int86(0x10,&inregs,&outregs);
}
}
图像组文件(如imggroup.lst)录入格式(每项占一行,编辑器用MS C6.0的PWB即可):
3
f:\zyf\
z1.img
z2.img
z3.img
如读者想进一步提高显示速度,方案如下:
1.窗口显示:只显示感兴趣的目标区域;
2.虚拟盘:把序列图像文件拷贝到虚拟盘(RAMDRIVE)上,文件读取速度明显提高;
3.预处理:将序列图像文件(*.img)的数据顺序写入一个影像文件(如image.mvi)。
4.DMA传输:使用DMA管理器直接将数据从RAM区传送至VRAM区。
笔者已备有位图(*.bmp)动画播放程序,以及*.bmp *.img的图像格式相互转换程序,愿与爱好图像处理的朋友们共享! 

作者:郑玉锋 

【在TVGA上实现全屏幕动画】相关文章:

1.J2ME在移动设备上实现动画程序方法

2.怎么在ppt中添加动画

3.怎样在flash中制作引导动画

4.在VBScript中实现函数的方法

5.素描在动画设计中的应用

6.在ppt中怎么做动画啊

7.肌理在动画设计中的运用

8.角色造型设计在动画中的应用

9.三维动画技术在动画影片中的应用