?? a.txt
字號:
break; setpixel(x+wx, y-wy, Color); setpixel(x-wx, y-wy, Color); setpixel(x+wx, y+wy, Color); setpixel(x-wx, y+wy, Color); }}inline void h_line(int x1,int x2,int y){ static short ftab[]={0xff,0x7f,0x3f,0x1f,0x0f,0x7,0x3,0x1}; static short btab[]={0x0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe}; short count; count=(x2-x1)>>3; if(count>1) { unsigned char *loc; loc=screen_ptr+((y*screen_width+x1)>>3); if(Color) { *(loc)|=ftab[x1&7]; memset(loc+1,0xff,count-1); *(loc+count)|= ftab[7-(x2&7)]; } else { *loc &=btab[x1&7]; memset(loc+1,0,count-1); *(loc+count)&=ftab[(x2&7)+1]; } } else line(x1, y, x2, y); }/* Composites */void rectangle(short x1, short y1, short x2, short y2){ line(x1, y1, x2, y1); line(x2, y1, x2, y2); line(x2, y2, x1, y2); line(x1, y2, x1, y1);}void bar(short x1,short y1,short x2,short y2){ for(;y1<y2;y1++) h_line(x1,x2,y1);}inline void clip_screen(short in_x, short in_y, short in_w, short in_h, short *out_x, short *out_y, short *out_w, short *out_h) { short swp; if (in_w < 0) { in_x += in_w; in_w = -in_w; } if (in_h < 0) { in_y += in_h; in_h = -in_h; } if (in_x < 0) { in_w -= in_x; in_x = 0; } if (in_y < 0) { in_h -= in_y; in_y = 0; } if (in_w > screen_width) { in_w = screen_width; } if (in_h > screen_height) { in_h = screen_height; } if (in_w < 0) { in_w = 0; } if (in_h < 0) { in_h = 0; } *out_x = in_x; *out_y = in_y; *out_w = in_w; *out_h = in_h;} void patternfill( short dest_x, short dest_y, short w, short h, unsigned char*dest, short dest_units_per_line);void fillrect(short x1, short y1, short x2, short y2){ short x, y, w, h; clip_screen(x1, y1, x2-x1, y2-y1, &x, &y, &w, &h); patternfill(x, y, w, h, screen_ptr, screen_width>>3);}void bitblt( short src_x, short src_y, short w, short h, short dest_x, short dest_y, unsigned char *src, short src_units_per_line, unsigned char *dest, short dest_units_per_line ) { /* todo: clip */ register char dx; unsigned short x,y; unsigned char src_off, dest_off; short dest_n; unsigned char dest_beg_mask, dest_end_mask; /* goto line y */ src += src_y * src_units_per_line; dest += dest_y * dest_units_per_line; /* goto UNIT-offset x */ src += src_x >>3; dest += dest_x >>3; /* determine number of affected units per line */ dest_n = ((dest_x + w + 8 - 1) >>3) - (dest_x >>3); /* determine PIXEL-offsets */ src_off = src_x & 7; dest_off = dest_x & 7; dx = dest_off - src_off; /* make masks to mask out untouchable destination */ dest_beg_mask = ~((unsigned char)(-1) >> dest_off); dest_end_mask = (unsigned char)(-1) >> ((dest_off + w) & 7); if (dest_end_mask == (unsigned char)(-1)) { /* bit stupid */ dest_end_mask = 0; } //printf("dx=%d\n", dx); //dump_unit("dest_beg_mask", dest_beg_mask); //dump_unit("dest_end_mask", dest_end_mask); for (y = 0; y < h; y++) { // process one line register unsigned char *sp; register unsigned char *dp; register unsigned char mask = 0; register unsigned char left, right; unsigned char s, d; sp = src; dp = dest; for (x = 0; x < dest_n; x++, sp++, dp++) { // process one unit if (dx < 0) { // first, don't care about masks left = *sp << (-dx); right = *(sp+1) >> (8 + dx); } else if (dx > 0) { // first, don't care about masks left = *(sp-1) << (8-dx); right = *(sp) >> (dx); } else { left = *sp; right = 0; } s = left | right; // combine with destination switch (Mode) { case MODE_SRC: default: d = s; break; case MODE_NOT_SRC: d = ~s; break; case MODE_SRC_OR_DST: d = *dp | s; break; case MODE_SRC_AND_DST: d = *dp & s; break; case MODE_SRC_XOR_DST: d = *dp ^ s; break; case MODE_NOT_SRC_OR_DST: d = *dp | ~s; break; case MODE_NOT_SRC_AND_DST: d = *dp & ~s; break; case MODE_NOT_SRC_XOR_DST: d = *dp ^ ~s; break; case MODE_SRC_OR_NOT_DST: d = ~*dp | s; break; case MODE_SRC_AND_NOT_DST: d = ~*dp & s; break; case MODE_SRC_XOR_NOT_DST: d = ~*dp ^ ~s; break; } mask = 0; if (x == 0) { mask |= dest_beg_mask; } if (x == dest_n-1) { mask |= dest_end_mask; } *dp = (*dp & mask) | (d & ~mask); } src += src_units_per_line; dest += dest_units_per_line; }}void patternfill( short dest_x, short dest_y, short w, short h, unsigned char*dest, short dest_units_per_line) { /* todo: clip */ register char dx; unsigned short x,y; unsigned char src_off, dest_off; short dest_n; unsigned char dest_beg_mask, dest_end_mask; const Pattern *pattern = patterns[P_Index]; /* goto line y */ dest += dest_y * dest_units_per_line; /* goto UNIT-offset x */ dest += dest_x / 8; /* determine number of affected units per line */ dest_n = (dest_x + w + 8 - 1) / 8 - dest_x / 8; /* determine PIXEL-offsets */ dest_off = dest_x % 8; /* make masks to mask out untouchable destination */ dest_beg_mask = ~((unsigned char)(-1) >> dest_off); dest_end_mask = (unsigned char)(-1) >> ((dest_off + w) % 8); if (dest_end_mask == (unsigned char)(-1)) { /* bit stupid */ dest_end_mask = 0; } for (y = 0; y < h; y++) { // process one line register unsigned char *dp; register unsigned char mask = 0; unsigned char s=pattern->data[(dest_y+y)%pattern->height], d; dp = dest; for (x = 0; x < dest_n; x++, dp++) { // combine with destination switch (Mode) { case MODE_SRC: default: d = s; break; case MODE_NOT_SRC: d = ~s; break; case MODE_SRC_OR_DST: d = *dp | s; break; case MODE_SRC_AND_DST: d = *dp & s; break; case MODE_SRC_XOR_DST: d = *dp ^ s; break; case MODE_NOT_SRC_OR_DST: d = *dp | ~s; break; case MODE_NOT_SRC_AND_DST: d = *dp & ~s; break; case MODE_NOT_SRC_XOR_DST: d = *dp ^ ~s; break; case MODE_SRC_OR_NOT_DST: d = ~*dp | s; break; case MODE_SRC_AND_NOT_DST: d = ~*dp & s; break; case MODE_SRC_XOR_NOT_DST: d = ~*dp ^ ~s; break; } mask = 0; if (x == 0) { mask |= dest_beg_mask; } if (x == dest_n-1) { mask |= dest_end_mask; } *dp = (*dp & mask) | (d & ~mask); } dest += dest_units_per_line; }}short initgraph(void){ struct fb_var_screeninfo screeninfo; screen_fd = open("/dev/fb0", O_RDWR); if (screen_fd == -1) { perror("Unable to open frame buffer device /dev/fb0"); return 0; } if (ioctl(screen_fd, FBIOGET_VSCREENINFO, &screeninfo)==-1) { perror("Unable to retrieve framebuffer information"); return 0; } //screen_width = screeninfo.xres_virtual; screen_width = 240;//screeninfo.xres_virtual; //screen_height = screeninfo.yres_virtual; screen_height = 320;//screeninfo.yres_virtual; //lyk modified it //E_Font = (unsigned char*)(screeninfo.english_font); //printf("E_Font Address %x %x\n",E_Font,screeninfo.english_font); //if(!E_Font) //E_Font=(unsigned char*)(0x8804); //E_Font=(unsigned char*)(0x8812); E_Font=fontdata_8x16;//(unsigned char*)(0x0004a690); screen_ptr = mmap(NULL, ((screen_height * screen_width*2)/4096+1)*4096, PROT_READ|PROT_WRITE, /*0*/MAP_SHARED, screen_fd, 0); if (screen_ptr==MAP_FAILED) { perror("Unable to mmap frame buffer"); close(screen_fd); return 0; } C_Font=fopen(CHINESE_FONT_FILE,"rb"); if(!C_Font) { perror("Unable to open Chinese font file"); close(screen_fd); return 0; } Color=1; return 1;}void closegraph(){ if(screen_fd!=-1) { close(screen_fd); } if(C_Font) fclose(C_Font);}void clearscreen(){ memset(screen_ptr,0,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){ short i, j, k, t,l=rwidth*height,m; int off,d; char *loc=screen_ptr+(off=((sy*screen_width+sx)>>3)); //printf("drawing bmp.\n"); for(t=0,k=0,i=0;i<height;i++,k+=screen_width>>3,t+=rwidth) for(j=0;(j<rwidth)&&(j<20);j++) { m=k+j; if(m+off>=3200) // if(m+off>=4000) return; loc[m]=pixel[t+j]; } //printf("draw_bmp finished.\n");}void ShowBMP(char *filename,short x,short y){ BMPHEAD bm; int tmpi; FILE *fp=fopen(filename,"rb"); char *buf,c; int i,j,t,width; long size; //printf("showing BMP KEYBORAD.\n"); if(!fp) return; //printf("freading...\n"); fread(&bm,1,sizeof(BMPHEAD),fp); //printf("fread finished.\n"); /*buf = (char*)&bm; for(tmpi=0;tmpi<sizeof(BMPHEAD);tmpi++) printf("%02x ",buf[tmpi]); printf("\n"); for(tmpi=0;tmpi<sizeof(BMPHEAD);tmpi+=2) printf("%04x ",*((short *)(buf+tmpi)) ); printf("\n"); for(tmpi=0;tmpi<sizeof(BMPHEAD);tmpi+=4) printf("%08x ",*((long *)(buf+tmpi)) ); printf("\n");*/ buf=(char*)&bm.bits; c=buf[0]; buf[0]=buf[1]; buf[1]=c; if(bm.bits!=0x100) { fclose(fp); printf("\ngraphic: Unsupported color bitmap\n"); return; } //printf("exchange width\n"); //printf("graphic:width=%08x\n",bm.width); bm.width = 160; /*buf=(char*)&bm.width; c=buf[0]; buf[0]=buf[3]; buf[3]=c; c=buf[1]; buf[1]=buf[2]; buf[2]=c; printf("graphic:width=%08x\n",bm.width); */ //printf("exchange height\n"); bm.height = 60; /* buf=(char*)&bm.height; c=buf[0]; buf[0]=buf[3]; buf[3]=c; c=buf[1]; buf[1]=buf[2]; buf[2]=c; */ width=(bm.width+7)>>3; if(width&3) width+=(4-(width&3)); //printf("bmphead=%d",sizeof(BMPHEAD)); //printf("width=%d,bm.height=%ld,size=%ld\n",width,bm.height,width*bm.height); buf=(char*)malloc(size=(width*bm.height)); //printf("malloc ok\n"); //fread(&i,1,8,fp); //fread(buf,1,100,fp); //lyk //fread(buf,1,8,fp); //fread(buf,1,1,fp); //lseek(fp,8,1); fread(buf,1,size,fp); fclose(fp); //printf("entering loop...\n"); for(i=0;i<(bm.height>>1); i++) for(t=i*width,j=0;j<width;j++) { c=buf[t+j]^0xff; buf[t+j]=buf[size-width-t+j]^0xff; buf[size-width-t+j]=c; } //printf("loop finished.\n"); draw_bmp(x,y,width,bm.height,buf); free(buf);}void V_scroll_screen(short height) //Up/Down Scroll{ short dir=(height<0); if(dir) height=-height; if(height<screen_height) { short nBytes=(screen_width>>3)*height, nCount=(screen_width>>3)*(screen_height-height); if(dir) //Down Scroll { memmove(screen_ptr+nBytes,screen_ptr,nCount); memset(screen_ptr,0,nBytes); } else //Up Scroll { memmove(screen_ptr,screen_ptr+nBytes,nCount); memset(screen_ptr+nCount,0,nBytes); } } 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){ int i,j,count=strlen(buf); short k,l,m=screen_width>>3; char pixel[32]; //printf("screen_height=%d\n",screen_height);#ifdef FONT if(!font) { puts("Please Init Chinese Enviroment First!"); return; }#endif for(i=0;i<count;) { // printf("gui:i=%d,count=%d\n",i,count); if(y>=screen_height) { memmove(screen_ptr,screen_ptr+320,2880); memset(screen_ptr+2880,0,320); y-=16; } if((buf[i]>=161)&&(buf[i+1]>=161)) { //int nHeadCount; //char cTmp; j=((buf[i]-161)*94+(buf[i+1]-161))<<5; fseek(C_Font,j,SEEK_SET); fread(pixel,32,1,C_Font); //Yongkui Lu changed it to fit the small head problem from Big head problem. /*for(nHeadCount=0;nHeadCount<32;nHeadCount+=2) { cTmp=pixel[nHeadCount]; pixel[nHeadCount]=pixel[nHeadCount+1];
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -