?? graphic.c
字號:
} printf("%d* %d\n",bmp_inf.biWidth,bmp_inf.biHeight); size=bmp_inf.biHeight*((bmp_inf.biWidth*3+3)/4*4); buf=(char*)malloc(size); buf1=(char*)malloc(bmp_inf.biWidth*bmp_inf.biHeight*2); fseek(fp,54L,0); fread(buf,1,size,fp); fclose(fp); for(i=0;i<(bmp_inf.biHeight>>1);i++) for(k=i*((bmp_inf.biWidth*3+3)/4)*4,j=0;j<bmp_inf.biWidth*3;j++) { Tmp=buf[k+j]; buf[k+j]=buf[size-k-bmp_inf.biWidth*3+j]; buf[size-k-bmp_inf.biWidth*3+j]=Tmp; } for(i=0;i<(bmp_inf.biHeight);i++) for(k=i*((bmp_inf.biWidth*3+3)/4)*4,m=i*bmp_inf.biWidth*2,j=0;j<bmp_inf.biWidth;j++) { red=(((buf[k+j*3])>>3))*2048; green=(buf[k+j*3+1]>>3)*64; blue=(buf[k+j*3+2]>>3); *(unsigned short *)(buf1+m+j*2)=red|green|blue; } color_565_draw_bmp(x,y,bmp_inf.biWidth,bmp_inf.biHeight,buf1); free(buf);free(buf1); }*/void ShowBMP(char *filename,short x,short y){ BMPHEAD bmp_inf; FILE *fp; char Tmp,*buf,*buf1,*buf2,c; int width,height; int red,green,blue; long aver_size,size,i,m,j,k; fp=fopen(filename,"rb"); if(!fp) return;fseek(fp,2L,0); fread(&bmp_inf.bfSize,1,52,fp);//printf("biBiCount %x\n",bmp_inf.biBitCount); if(bmp_inf.biBitCount!=1&bmp_inf.biBitCount!=16&bmp_inf.biBitCount!=24) { fclose(fp); puts("Unsupported 2|16color bitmap!\n"); printf("bitcolor=%d\n",*((short*)&bmp_inf.biBitCount)); return; } else if(bmp_inf.biBitCount==1) //Show black and white { printf("%d* %d\n",bmp_inf.biWidth,bmp_inf.biHeight); aver_size=((bmp_inf.biWidth+15)/16)*2; //line size printf("aversize=%d\n",aver_size); size=aver_size*bmp_inf.biHeight; buf=(char*)malloc(size);fseek(fp,62L,0); fread(buf,1,size,fp); fclose(fp); for(i=0;i<(bmp_inf.biHeight>>1);i++) for(k=i*aver_size,j=0;j<aver_size;j++) { Tmp=buf[k+j]; buf[k+j]=buf[size-k-aver_size+j]; buf[size-k-aver_size+j]=Tmp; } for(i=0;i<size;i++) buf[i]^=0xff; printf("the width=%d\nthe height=%d\n",bmp_inf.biWidth,bmp_inf.biHeight); my_draw_bmp(x,y,bmp_inf.biWidth,bmp_inf.biHeight,buf); free(buf); } else if(bmp_inf.biBitCount==16) //show 16_bit BMP SHOW_16_color_bmp {size=bmp_inf.biWidth*bmp_inf.biHeight*2; buf=(char*)malloc(size); fseek(fp,54L,0); fread(buf,1,size,fp); fclose(fp); for(i=0;i<(bmp_inf.biHeight>>1);i++) for(k=i*bmp_inf.biWidth*2,j=0;j<bmp_inf.biWidth*2;j++) { Tmp=buf[k+j]; buf[k+j]=buf[size-k-bmp_inf.biWidth*2+j]; buf[size-k-bmp_inf.biWidth*2+j]=Tmp; } color_555_draw_bmp(x,y, bmp_inf.biWidth,bmp_inf.biHeight,buf); // else // color_565_draw_bmp(x,y,bmp_inf.biWidth,bmp_inf.biHeight,buf); free(buf);} else if(bmp_inf.biBitCount==24) {// printf("%d* %d\n",bmp_inf.biWidth,bmp_inf.biHeight); size=bmp_inf.biHeight*((bmp_inf.biWidth*3+3)/4*4); buf=(char*)malloc(size); buf1=(char*)malloc(bmp_inf.biWidth*bmp_inf.biHeight*2); fseek(fp,54L,0); fread(buf,1,size,fp); fclose(fp); for(i=0;i<(bmp_inf.biHeight>>1);i++) for(k=i*((bmp_inf.biWidth*3+3)/4)*4,j=0;j<bmp_inf.biWidth*3;j++) { Tmp=buf[k+j]; buf[k+j]=buf[size-k-bmp_inf.biWidth*3+j]; buf[size-k-bmp_inf.biWidth*3+j]=Tmp; } for(i=0;i<(bmp_inf.biHeight);i++) for(k=i*((bmp_inf.biWidth*3+3)/4)*4,m=i*bmp_inf.biWidth*2,j=0;j<bmp_inf.biWidth;j++) { /* red=(((buf[k+j*3+2])>>3))*2048; green=(buf[k+j*3+1]>>3)*64; blue=(buf[k+j*3]>>3);*/ red=((float)(buf[k+j*3+2]))/255*31+0.5; green=((float)(buf[k+j*3+1]))/255*63+0.5; blue=((float)(buf[k+j*3]))/255*31+0.5; *(unsigned short *)(buf1+m+j*2)=(red<<11)|(green<<5)|(blue); // *(unsigned short *)(buf1+m+j*2)=red|green|blue; } color_565_draw_bmp(x,y,bmp_inf.biWidth,bmp_inf.biHeight,buf1); free(buf); free(buf1); }}void ShowBuf(char *Buf,short x,short y){ BMPHEAD bmp_inf; char Tmp,*buf,*buf1,*buf2,c; int width,height; int red,green,blue; long aver_size,size,i,m,j,k; memcpy(&bmp_inf.bfSize,(Buf+2),52); //printf("biBiCount %x\n",bmp_inf.biBitCount); if(bmp_inf.biBitCount!=1&bmp_inf.biBitCount!=16&bmp_inf.biBitCount!=24) { //fclose(fp); puts("Unsupported 2|16color bitmap!\n"); printf("bitcolor=%d\n",*((short*)&bmp_inf.biBitCount)); return; } else if(bmp_inf.biBitCount==1) //Show black and white { printf("%d* %d\n",bmp_inf.biWidth,bmp_inf.biHeight); aver_size=((bmp_inf.biWidth+15)/16)*2; //line size printf("aversize=%d\n",aver_size); size=aver_size*bmp_inf.biHeight; buf=(char*)malloc(size); memcpy(buf,(Buf+62),size); //fseek(fp,62L,0); // fread(buf,1,size,fp); // fclose(fp); for(i=0;i<(bmp_inf.biHeight>>1);i++) for(k=i*aver_size,j=0;j<aver_size;j++) { Tmp=buf[k+j]; buf[k+j]=buf[size-k-aver_size+j]; buf[size-k-aver_size+j]=Tmp; } for(i=0;i<size;i++) buf[i]^=0xff; printf("the width=%d\nthe height=%d\n",bmp_inf.biWidth,bmp_inf.biHeight); my_draw_bmp(x,y,bmp_inf.biWidth,bmp_inf.biHeight,buf); free(buf); } else if(bmp_inf.biBitCount==16) //show 16_bit BMP SHOW_16_color_bmp {size=bmp_inf.biWidth*bmp_inf.biHeight*2; buf=(char*)malloc(size); memcpy(buf,(Buf+54),size);// fseek(fp,54L,0); fread(buf,1,size,fp);// fclose(fp); for(i=0;i<(bmp_inf.biHeight>>1);i++) for(k=i*bmp_inf.biWidth*2,j=0;j<bmp_inf.biWidth*2;j++) { Tmp=buf[k+j]; buf[k+j]=buf[size-k-bmp_inf.biWidth*2+j]; buf[size-k-bmp_inf.biWidth*2+j]=Tmp; } color_555_draw_bmp(x,y, bmp_inf.biWidth,bmp_inf.biHeight,buf); // else // color_565_draw_bmp(x,y,bmp_inf.biWidth,bmp_inf.biHeight,buf); free(buf);} else if(bmp_inf.biBitCount==24) { printf("%d* %d\n",bmp_inf.biWidth,bmp_inf.biHeight); size=bmp_inf.biHeight*((bmp_inf.biWidth*3+3)/4*4); buf=(char*)malloc(size); buf1=(char*)malloc(bmp_inf.biWidth*bmp_inf.biHeight*2); memcpy(buf,(Buf+54),size); // fseek(fp,54L,0); // fread(buf,1,size,fp);// fclose(fp); for(i=0;i<(bmp_inf.biHeight>>1);i++) for(k=i*((bmp_inf.biWidth*3+3)/4)*4,j=0;j<bmp_inf.biWidth*3;j++) { Tmp=buf[k+j]; buf[k+j]=buf[size-k-bmp_inf.biWidth*3+j]; buf[size-k-bmp_inf.biWidth*3+j]=Tmp; } for(i=0;i<(bmp_inf.biHeight);i++) for(k=i*((bmp_inf.biWidth*3+3)/4)*4,m=i*bmp_inf.biWidth*2,j=0;j<bmp_inf.biWidth;j++) { /* red=(((buf[k+j*3+2])>>3))*2048; green=(buf[k+j*3+1]>>3)*64; blue=(buf[k+j*3]>>3);*/ red=((float)(buf[k+j*3+2]))/255*31+0.5; green=((float)(buf[k+j*3+1]))/255*63+0.5; blue=((float)(buf[k+j*3]))/255*31+0.5; *(unsigned short *)(buf1+m+j*2)=(red<<11)|(green<<5)|(blue); // *(unsigned short *)(buf1+m+j*2)=red|green|blue; } color_565_draw_bmp(x,y,bmp_inf.biWidth,bmp_inf.biHeight,buf1); free(buf); free(buf1); }}void V_scroll_screen(short height) //Up/Down Scroll{ short dir=(height<0); if(dir) height=-height; if(height<screen_height) { long nBytes=height*240*2;/////////// long nCount=240*2*(screen_height-height); if(dir) //Down Scroll memmove(screen_ptr+nBytes,screen_ptr,nCount); else //Up Scroll memmove(screen_ptr,screen_ptr+nBytes,nCount); } else clearscreen(); }void H_scroll_screen(short width) //Left Scroll{ short dir=(width<0); if(dir) width=-width; if(width<screen_width) { if(width&7) //Check whether it is byte aligned { short nCount=screen_width*screen_height>>3; static unsigned char mskr[]={0,1,3,7,0xf,0x1f,0x3f,0x7f}, mskl[]={0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe}, buf[3200]; unsigned char /*buf,*/c,flag=0,d; short start=(width>>3),length=(width&7),i,j,wid=(screen_width>>3),off; memcpy(buf,screen_ptr,nCount); if(dir) { for(off=0,j=0;j<screen_height;j++,off+=wid) { for(flag=0,i=wid-1;i>=start;i--) { d=c=*(buf+off+i); c<<=length; if(flag) c|=(flag>>(8-length)); flag=d&mskl[length]; *(buf+off+i)=c; } if(start) for(i=wid-start;i<wid;i++) { *(buf+off+i)=0; } } } else for(off=0,j=0;j<screen_height;j++,off+=wid) { for(flag=0,i=start;i<wid;i++) { d=c=*(buf+off+i); c>>=length; if(flag) c|=(flag<<(8-length)); flag=d&mskr[length]; *(buf+off+i)=c; } if(start) for(i=0;i<start;i++) { *(buf+off+i)=0; } } memcpy(screen_ptr,buf,nCount); } else { short i,j=0,wid=screen_width>>3; width>>=3; for(i=0;i<screen_height;i++,j+=wid) { memmove(screen_ptr+j+width,screen_ptr+j,wid-width); memset(screen_ptr+j,0,width); } } } else clearscreen();}void textout(short x,short y,unsigned char *buf,unsigned short color,unsigned short groundcolor){ int i,j,count=strlen(buf); short k,l,m=screen_width>>3; char pixel[32];#ifdef FONT if(!font) { puts("Please Init Chinese Enviroment First!"); // printf(X\n"); return; }#endif if(x<0) x=0;else if(x>240) x=240;if(y<0) y=0;else if(y>320) y=320; for(i=0;i<count;) //1 { if((buf[i]>=161)&&(buf[i+1]>=161))///2 { j=((buf[i]-161)*94+(buf[i+1]-161))<<5; fseek(C_Font,j,SEEK_SET); fread(pixel,32,1,C_Font); if((x+16)>screen_width) { y+=16; x=0; } if(y+16>screen_height) {V_scroll_screen(y+16-screen_height);////up XY_clearscreen(0,screen_height-16,screen_width-1,screen_height-1); y=screen_height-16; } draw_bmp(x,y,2,16,pixel,color,groundcolor); x+=16; i+=2; } else { if(buf[i]=='\n') {if(y+16>screen_height) {V_scroll_screen(y+16-screen_height);////up XY_clearscreen(0,screen_height-16,screen_width-1,screen_height-1); y=screen_height-16; } else y+=16; x=0; } else {if((x+8)>screen_width) { y+=16; x=0; } if(y+16>screen_height) {V_scroll_screen(y+16-screen_height);////up XY_clearscreen(0,screen_height-16,screen_width-1,screen_height-1); y=screen_height-16; } draw_bmp(x,y,1,16,E_Font+(buf[i]<<4),color,groundcolor); x+=8; } i++; }///end 2 }//end 1 }void setmode(CopyMode mode){ Mode=mode;}CopyMode getmode(void) { return Mode; }void setcolor(short color){ Color=color;}UINT getcolor(void){ return Color;}void setfillpattern(PatternIndex index){ P_Index=index; }PatternIndex getfillpattern(void){ return P_Index; }void moveto(short x,short y){ X=x;Y=y;}void lineto(short x,short y){ line(x,y,X,Y); X=x;Y=y;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -