⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphic.c

📁 基于s3c2410gui(图形用户界面)应用程序源码!
💻 C
📖 第 1 页 / 共 2 页
字号:
// for(i=0;i<h_y;i++)//  memset(screen_ptr+240*2*y1+2*x1+i*240*2,0,w_x*2); memset(screen_ptr+240*2*y1+2*x1,0,h_y*w_x*2);}void clearscreen(){	memset(screen_ptr,0,screen_width*screen_height*2);}void clearscreen_white(){        memset(screen_ptr,0xff,screen_width*screen_height*2);}void draw_xbm(short sx, short sy, short width, short height, char* pixel){	short i, j, k, t,l=(width>>=3)*height,m,wid=screen_width>>3;	short d,off;	char *loc=screen_ptr+(off=((sy*screen_width+sx)>>3));          for(k=0,i=0;i<height;i++,k+=wid)          for(j=0;(j<width)&&(j<20);j++) 	{	      d=0;	      for(m=0;m<8;m++)	        if(pixel[k+j]&masktab[m]) d|=masktab[7-m];	      t=k+j;              if((t+off)>=3200) return;	      loc[t]=d;			       	    	}}void draw_bmp(short sx, short sy, short rwidth, short height, char* pixel,unsigned short color,unsigned short groundcolor){	short i, j, k;        char flag=0;	char *loc=screen_ptr+sx*2+sy*240*2;	for(j=0;j<height;j++)	for(k=0;k<rwidth;k++)	 for(i=0;i<8;i++)          {flag= *(pixel+j*rwidth+k) & masktab[i];            if(flag)            {// *(loc+j*240*2+k*16+i*2)=0x00;             // *(loc+j*240*2+k*16+i*2+1)=0x00;	      *(unsigned short*)(loc+j*240*2+k*16+i*2)=color;             }          else{// *(loc+j*240*2+k*16+i*2)=0xff;               // *(loc+j*240*2+k*16+i*2+1)=0xff;		*(unsigned short*)(loc+j*240*2+k*16+i*2)=groundcolor;                              } 	}}void my_draw_bmp(short x,short y,unsigned short width,unsigned short height,char *pixel){short i,j; long aver_size=((width+31)/32)*4; char masktab[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; for(j=0;(y+j)<ScreenHeight&&(y+j)>=0&&j<height;j++)     //0---height;  for(i=0;(x+i)<ScreenWidth&&(x+i)>=0&&i<width;i++)      //0---width ;          if(*(pixel+j*aver_size+i/8) & masktab[i%8])//judge pixel "0"or "1";                      { *(screen_ptr+(y+j)*ScreenWidth*2+2*(i+x))=0x00;                 *(screen_ptr+(y+j)*ScreenWidth*2+2*(i+x)+1)=0x00;                         }             else{ *(screen_ptr+(y+j)*ScreenWidth*2+2*(i+x))=0xff;                   *(screen_ptr+(y+j)*ScreenWidth*2+2*(i+x)+1)=0xff;                }}inline void color_dot_bmp(short x,short y,char *buf) {if(y>0&&y<ScreenHeight)    if(x>0&&x<ScreenWidth)     {*(screen_ptr+y*240*2+2*x)=*buf;      *(screen_ptr+y*240*2+2*x+1)=*(buf+1);     }  }void color_555_draw_bmp(short x,short y,unsigned short width,unsigned short height,char *buf){   long i,j,offset;    unsigned short tmp,red,green,blue;   for(j=y;j<ScreenHeight&&(j-y)<height;j++)        for(i=x;i<ScreenWidth&&(i-x)<width;i++)           { offset=(j-y)*width*2+(i-x)*2;             tmp=*(unsigned short*)(buf+offset);             red=(tmp&0x7c00)<<1;             green=(tmp&0x03e0)<<1;             tmp&=0x001f;             tmp|=red|green;            *(unsigned short*)(screen_ptr+j*240*2+2*i)=tmp;           } }void color_565_draw_bmp(short x,short y,unsigned short width,unsigned short height,char *buf){   long i,j,offset;    unsigned short tmp,red,green,blue;   for(j=y;j<ScreenHeight&&(j-y)<height;j++)        for(i=x;i<ScreenWidth&&(i-x)<width;i++)           { offset=(j-y)*width*2+(i-x)*2;             tmp=*(unsigned short*)(buf+offset);             /*red=tmp&0xf800;             green=(tmp&0x07e0);             tmp=tmp&0x001f;             tmp=red|green|tmp;             */             *(unsigned short*)(screen_ptr+j*ScreenWidth*2+2*i)=tmp;           /*  *(screen_ptr+j*ScreenWidth*2+2*i)=*(buf+offset);             *(screen_ptr+j*ScreenWidth*2+2*i+1)=*(buf+offset+1);*/                 }}/////////////void testbmp(){long i,j; short k=0x20;for(j=0;j<160;j++){ for(i=0;i<240;i++)     { *(screen_ptr+j*240*2+2*i)=0x00;       *(screen_ptr+j*240*2+2*i+1)=0x40;        }//  k=k+2;}}////////////////////////////*  void ShowBMP_16_color(char *filename,short x,short y){ BMPHEAD bmp_inf;  FILE *fp;  char Tmp,c,*buf,*buf1,*buf2;  int  width,height;  int bmptype=0;  long size,i,j,k;  fp=fopen(filename,"rb");  if(!fp) return;fseek(fp,2L,0);  fread(&bmp_inf.bfSize,1,52,fp);  if(bmp_inf.biBitCount!=16)        {         fclose(fp);         puts("Unsupported 16_color bitmap!\n");         printf("bitcolor=%d\n",bmp_inf.biBitCount);         return;        }s1: printf("%d* %d\n",bmp_inf.biWidth,bmp_inf.biHeight);  size=bmp_inf.biWidth*bmp_inf.biHeight*2;  buf=(char*)malloc(size);  fseek(fp,70L,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);}*//*void ShowBMP_24_color(char *filename,short x,short y) {BMPHEAD bmp_inf;  FILE *fp;  char Tmp,c,*buf,*buf1,*buf2;  int  width,height;  int bmptype=0;  long size,i,j,k,m;  short red,green,blue;  float redtmp,greentmp,bluetmp;  fp=fopen(filename,"rb");  if(!fp) return;  fseek(fp,2L,0);  fread(&bmp_inf.bfSize,1,52,fp);  if(bmp_inf.biBitCount!=24)        {         fclose(fp);         puts("Unsupported 24_color bitmap!\n");         printf("bitcolor=%d\n",bmp_inf.biBitCount);         return;        }  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,unsigned short color){	line(x,y,X,Y,color);	X=x;Y=y;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -