




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include stdio.h#include math.h#include graphics.h#include string.h#include dos.h#include stdlib.h#include alloc.h#include conio.h#include bios.h#include mem.h#include dir.h#include ctype.h#define LEFT 75#define RIGHT 77#define UP 72#define DOWN 80#define ESC 0X001b#define ENTER 0X1C0d#define Home 71#define End 79#define Alt_x 45#define Ctrl_LEFT 115#define Ctrl_RIGHT 116 #define Ctrl_Home 119#define Ctrl_End 117#define PgUp 73#define PgDn 81typedef struct /定义结构体 int topx,topy; int bottomx,bottomy; char name20; char color;BUTTON;union KEY /定义共用体 int k; char c2;key1;struct BMP_Head char ID2; /*总是BM*/ unsigned long FileLength; /*文件大小,以字节为单位*/ int Reserved1; /*必须为0*/ int Reserved2; /*必须为0*/ unsigned long ImagePosition; /*图像数据的起始位置*/ unsigned long HeadLength; /*文件头的大小*/ unsigned long ImageWidth; /*图像宽度*/ unsigned long ImageHeight; /*图像高度*/ int BitPlane; /*必须为1*/ int ColorBit; /*每个像素的位数(1.4.8或24)*/ unsigned long CompressMethod; /*图像所用的压缩类型*/ unsigned long ImageLength; /*图像字节数的多少*/ unsigned long HorizontalDefinition; /*图像水平分辨率*/ unsigned long VerticalDefinition; /*图像垂直分辨率*/ unsigned long UsedColorNumber; /*图像实际使用的颜色数*/ unsigned long ImportantColorNumber; /*重要的颜色数*/bmp_head;struct BMP_Palette / 定义调色板大小 unsigned char palette2564;bmp_palette; unsigned char *i_img;unsigned char *o_img;unsigned char *shadow_buf;unsigned int palette_size;unsigned long img_row,img_col,line_size;unsigned long w=256l,D=256l;int INITmode;void SetScrMode(int); /设置显示模式int GetScrMode(void); /获取显示模式void InitGraphics(void); / 初始化图形系统void ReadBMPHeadInfo(char*); /读取BMP 图像文件头void DisplayImgHeadInfo(char*);void DisplayRoamImage(unsigned char *,long); /显示内存缓冲区中图像void SaveBufToFile(unsigned char *); /将内存缓冲区中的图像存入磁盘void Display8BitBMPImage(char*); /从磁盘中读取图像并放入内存缓冲上区中,然后调用 DisplayRoamImage()显示void InitGraphics(void) int g_driver,g_mode,g_error; closegraph(); g_driver=DETECT; /让系统自动检测图形适配器的最高分 /辨模式的,并装入相应的图形驱动程序 g_error=0; initgraph(&g_driver,&g_mode,); g_error=graphresult(); if(g_error0); outtextxy(30,120,initgraph error!); exit(1); restorecrtmode(); void ReadBMPHeadInfo(char *filename) FILE *fp; fp=fopen(c:lena.bmp:,rb); if(fp=NULL) printf(cannot open this filen); exit(0); fread(&bmp_head,sizeof(bmp_head),1,fp); if(bmp_head.ID0!=B)&(bmp_head.ID1!=M) printf(this file is not BMP filen); fclose(fp); exit(0); palette_size=bmp_head.ImagePosition-sizeof(bmp_head); fread(&bmp_palette,1,palette_size,fp); img_row=bmp_head.ImageHeight; img_col=bmp_head.ImageWidth; line_size=(bmp_head.ImageWidth*bmp_head.ColorBit+31)/32*4; fclose(fp); void load_data(char *filename,unsigned char *in_img)FILE*fp;int i,n;unsigned char *buffer;fp=fopen(c:lena.bmp,rb);if(fp=NULL) printf(Cannot open this filen); exit(0); fread(&bmp_head,sizeof(bmp_head),1,fp);if(bmp_head.ID0!=B)&(bmp_head.ID1!=M) printf(this file is not BMP filen);fclose(fp);exit(0);palette_size=bmp_head.ImagePosition-sizeof(bmp_head);fread(&bmp_palette,1,palette_size,fp);img_row=bmp_head.ImageHeight;img_col=bmp_head.ImageWidth;/img_size=(bmp_head.ImageWidth*bim_head.ColorBit+31)/32*4;line_size=(bmp_head.ImageWidth*bmp_head.ColorBit+31)/32*4 ;buffer=in_img;for(i=0;ifarcoreleft() printf(no enough memory);exit(0); mem_ptr=(unsigned char *)farmalloc(buffer_size); if(mem_ptr=NULL) printf(cannot allocate memoryn);exit(0); return(mem_ptr);void save_data(char *filename,unsigned char *buffer)int i,n;FILE* fp;fp=fopen(c:lena.bmp,wb);if(fp=NULL) exit(0);fwrite(&bmp_head,sizeof(bmp_head),1,fp);n=bmp_head.ImagePosition-sizeof(bmp_head);fwrite(&bmp_palette,n,1,fp);for(i=0;iimg_row;i+)fwrite(void*)buffer,line_size,1,fp);buffer+=line_size;fclose(fp); void set_grey_palette(void)int i,j;outportb(0x3c8,0x00);for(i=0;i=0;j-);outportb(0x3c9,i2); void set_color_palette( unsigned char palette4,int length) int i,j,ch,k;outportb(0x3c8,0x00);for(i=0;i=0;j-)ch=paletteij2;outportb(0x3c9,ch); void SetScrMode(int mode) union REGS reg;reg.h.ah=0;reg.h.al=mode;int86(0x10,®,®); int GetScrMode() union REGS reg;reg.h.ah=0xf;int86(0x10,®,®);return(int)reg.h.al); void SaveBufToFile( unsigned char * result_image) int key1,key2;char save_filename80;struct ffblk f; /ffblk 是一个 struct,定义在 dir.h 中,用于保存查找到的文件信息。 /结合 findfirst() findnext(),可以实现文件的查找并可得到文件相关信息。printf(Do you want to save this tranformed image?(Y/N)n);key1=getch();if(toupper(key1)=Y)dokey2=0;printf(nPlease input the filename.BMP;);scanf(%s,save_filename);if(findfirst(save_filename,&f,0)save_data(save_filename,result_image);printf(nnaSave File Successfully!n);else printf(nImage%s has exited!n,save_filename);printf(OverWrite/Abort/Retry-an);key2=toupper(getche();if(key2=O)save_data(save_filename,result_image);printf(nnaOverWrite Successfully!n);while(key2=R); printf(nPress any Key to continue.);getch(); void DisplayImgHeadInfo( char *filename) unsigned long buffer_size;ReadBMPHeadInfo(filename);buffer_size=img_row*line_size;printf(nn%s Image Information;nn,filename);printf(Height: %ldn , img_row);printf(Width: %ldn,img_col);printf(Line Size: %ldn, line_size);printf(Image Length: %ldn, buffer_size);printf(Palette size: %dnn,palette_size);printf(Press any key to continue.n);getch(); void DisplayRoamImage( unsigned char *image_data,long img_row) int i,j,k,seg,off,row_remain,col_remain;int disp_row,disp_col,disp_row1;unsigned char *data;if(row_remain=(int)img_row-200)0)disp_row=200;else disp_row=img_row;row_remain=0;if(col_remain=(int)img_col-320)0)disp_col=320;elsedisp_col=img_col;col_remain=0;j=0;k=0;dodata=image_data+(img_row-j)*line_size+k;if(j0)data=image_data+img_row*line_size+k;clrscr();for(i=(-j);idisp_row;i+)data-=line_size;seg=FP_SEG(data);off=FP_OFF(data);movedata(seg,off,0xa000,(long)i*320,disp_col);elseif(jrow_remain)for(i=0;idisp_row;i+)data-=line_size;seg=FP_SEG(data);off=FP_OFF(data);movedata(seg,off,0xa000,(long)i*320,disp_col);elsedisp_row1=disp_row-(j-row_remain); /?clrscr();for(i=0;idisp_row1;i+)data-=line_size;seg=FP_SEG(data);off=FP_OFF(data);movedata(seg,off,0xa000,(long)i*320,disp_col);key1.k=bioskey(0); /函数原型:int bioskey (int cmd),bioskey()完成直接键盘操作,cmd的值决定执行什么操作。 /当cmd是0,bioskey()返回下一个在键盘键入的值(它将等待到按下一个键)if(key1.c0=0)switch(key1.c1)case DOWN:j+;break;case UP:j-;break;case End:if(j=row_remain)printf(a);break;elsej=row_remain;break;case Home:if(j=0)printf(n);break;elsej=0;break;case RIGHT:if(k=col_remain)printf(a);break;else k+;break;case LEFT:if(k=0)printf(a);break;else k-;break;case Ctrl_Home: if(k=0)printf(a);break;elsek=0;break;case Ctrl_End:if(k=col_remain)printf(a);break;elsek=col_remain;break;case Alt_x:return;while(1); void Display8BitBMPImage(char* filename)ReadBMPHeadInfo(filename);i_img=alloc_mem(img_row*line_size);load_data(filename,i_img);DisplayImgHeadInfo(filename);SetScrMode(0x13);set_color_palette(bmp_palette.palette,palette_size/4);DisplayRoamImage(i_img,img_row);SetScrMode(INITmode); /*-*/* The following is image processing subfunction*/*-*/#include math.h#define ff(i,j) ip(long)(i)*lx+j#define gg(i,j) jp(long)(i)*lx+jvoid rotate (unsigned char *ip,unsigned char *jp,unsigned long lx,unsigned long ly,double theta)int temp;unsigned long i,j;long x,y,oldx,oldy;double d0,d1,fx,fy,pi2,temp1,temp2;double s,c,angle;pi2=8*atan(1.0);angle =(theta/360.0)*pi2;for(i=0l;ily;i+)for(j=0l;jlx;j+)gg(i,j)=0;for(y=0l;yly;y+)for(x=0l;xlx;x+)c=cos(angle);s=sin(angle);fx=(double)x-(double)(lx-1l)/2.0)*c-(double)y-(double)(ly-1l)/2.0)*s+(lx-1l)/2.0;fx=(double)x-(double)(lx-1l)/2.0)*s-(double)y-(double)(ly-1l)/2.0)*c+(ly-1l)/2.0;oldx=(long)floor(fx);oldy=(long)floor(fy);d0=fy-ol
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 绿色环保低碳建材产业园建设项目技术方案
- 腰痛考试题多选题及答案
- 堤防地质勘察与风险评估
- 水库扩建工程施工方案
- 企业离职补偿及员工培训协议范本
- 双方财产清算及分期偿还债务协议书
- 商业设施租赁合同范本:购物中心租赁合同
- 离婚协议子女抚养权及财产分割详细范本指南
- 研究型大学全职教师聘任与科研成果转化合同
- 采购文员考试试题及答案
- 浅谈国内外深基坑支护技术的现状及进展
- 网络舆情应对及处置
- 工业数据采集技术及应用 -配置能源采集仪表参数
- 《应急救援知识》课件
- 【一例重症肺炎的个案护理案例报告6000字(论文)】
- 电梯使用维护说明书
- 专业方向证明
- 范里安-微观经济学:现代观点
- 传热学全套PPT完整教学课件
- 部编版六年级道德与法治上册第5课《国家机构有哪些》优秀课件
- 民族区域自治制度课件 【核心知识精讲精思】 高中政治统编版必修三政治与法治
评论
0/150
提交评论