📄 ads.c
字号:
dp1 = _dp1 + (sy >> 16) * w1; } } break; case 2: { int y, sy; sy = 0; for (y = 0; y < h2;) { int sx = 0; uchar *dp2old = dp2; int x; x = 0; /* This can be greatly optimized with loop */ /* unrolling; omitted to save space. */ while (x < w2) { *(unsigned short *) (dp2 + x * 2) = *(unsigned short *) (dp1 + (sx >> 16) * 2); sx += xfactor; x++; } dp2 += w2 * 2; y++; while (y < h2) { int l; int syint = sy >> 16; sy += yfactor; if ((sy >> 16) != syint) break; /* Copy identical lines. */ l = dp2 - dp2old; memcpy(dp2, dp2old, l); dp2old = dp2; dp2 += l; y++; } dp1 = _dp1 + (sy >> 16) * w1 * 2; } } break; case 3: { int y, sy; sy = 0; for (y = 0; y < h2;) { int sx = 0; uchar *dp2old = dp2; int x; x = 0; /* This can be greatly optimized with loop */ /* unrolling; omitted to save space. */ while (x < w2) { *(unsigned short *) (dp2 + x * 3) = *(unsigned short *) (dp1 + (sx >> 16) * 3); *(unsigned char *) (dp2 + x * 3 + 2) = *(unsigned char *) (dp1 + (sx >> 16) * 3 + 2); sx += xfactor; x++; } dp2 += w2 * 3; y++; while (y < h2) { int l; int syint = sy >> 16; sy += yfactor; if ((sy >> 16) != syint) break; /* Copy identical lines. */ l = dp2 - dp2old; memcpy(dp2, dp2old, l); dp2old = dp2; dp2 += l; y++; } dp1 = _dp1 + (sy >> 16) * w1 * 3; } } break; case 4: { int y, sy; sy = 0; for (y = 0; y < h2;) { int sx = 0; uchar *dp2old = dp2; int x; x = 0; /* This can be greatly optimized with loop */ /* unrolling; omitted to save space. */ while (x < w2) { *(unsigned *) (dp2 + x * 4) = *(unsigned *) (dp1 + (sx >> 16) * 4); sx += xfactor; x++; } dp2 += w2 * 4; y++; while (y < h2) { int l; int syint = sy >> 16; sy += yfactor; if ((sy >> 16) != syint) break; /* Copy identical lines. */ l = dp2 - dp2old; memcpy(dp2, dp2old, l); dp2old = dp2; dp2 += l; y++; } dp1 = _dp1 + (sy >> 16) * w1 * 4; } } break; } return 0;}/****************************************************************************/static int copybox (GAL_GC gc, int x, int y, int w, int h, int nx, int ny){ int ret; unsigned char *temp_buf = (unsigned char *)alloca(gc.ads->stride * h + 1 ); ret = getbox(gc,x,y,w,h,temp_buf); if ( ret == -1 ) return -1; ret = putbox(gc,nx,ny,w,h,temp_buf); if ( ret == -1 ) return -1; return 0;}static int crossblit (GAL_GC src, int sx, int sy, int sw, int sh, GAL_GC dst, int dx, int dy){ int ret; unsigned char *temp_buf = (unsigned char *)alloca(src.ads->stride * sh + 1 ); ret = getbox(src,sx,sy,sw,sh,temp_buf); if ( ret == -1 ) return -1; ret = putbox(dst,dx,dy,sw,sh,temp_buf); if ( ret == -1 ) return -1; return 0;}// Horizontal line operaionsstatic int drawhline (GAL_GC gc, int x, int y, int w, gal_pixel pixel){ int i,x1,y1,x2,y2,ret,ww; unsigned char *dest; getclipping(gc,&x1,&y1,&x2,&y2); ww = w; ww += x; ret = getclippingrect(x1,y1,x2,y2,&x,&y,&ww,&y); if ( ret == -1 ) return -1; ww -= x; dest = gc.ads->fb_buf + (gc.ads->stride)*y + (gc.ads->stride)*x/MAX_X;// for ( i = 0; i < ww; i++ )// { // *(dest++) = pixel;// } memset(dest,pixel,ww); return 0;}#if 0static int puthline (GAL_GC gc, int x, int y, int w, void* buf){ int i,k,x1,x2,y1,y2,ret,ww; unsigned char *dest; k = 0; getclipping(gc,&x1,&y1,&x2,&y2); ww = w; ww += x; ret = getclippingrect(x1,y1,x2,y2,&x,&y,&ww,&y); if ( ret == -1 ) return -1; ww -= x; dest = gc.ads->fb_buf + (gc.ads->stride)*y + (gc.ads->stride)*x/MAX_X;// for ( i = 0; i < ww; i++ )// {// *(dest++) = (unsigned char *)buf[k++] ;// } memcpy(dest,buf,ww); return 0;}static int gethline (GAL_GC gc, int x, int y, int w, void* buf){ int i,k,x1,y1,x2,y2; unsigned char *dest; k = 0; getclipping(gc,&x1,&y1,&x2,&y2); dest = gc.ads->fb_buf+(gc.ads->stride)*y+(gc.ads->stride)*x/MAX_X;// for ( i = 0; i < w; i++ )// {// if ( x+i <= x2 && x+i >= 0)// { // (unsigned char *)buf[k] = *(dest++); memcpy(buf,dest,min(x2-x,w)); // }// k++;// } return 0;}#endif// Vertical line operationsstatic int drawvline (GAL_GC gc, int x, int y, int h, gal_pixel pixel){ int i,x1,y1,x2,y2,ret,hh; unsigned char *dest; getclipping(gc,&x1,&y1,&x2,&y2); hh = h; hh += y; ret = getclippingrect(x1,y1,x2,y2,&x,&y,&x,&hh); if ( ret == -1 ) return -1; hh -= y; for ( i = 0; i < hh; i++ ) { dest = gc.ads->fb_buf + (gc.ads->stride)*(y+i) + (gc.ads->stride)*x/MAX_X; dest+=gc.ads->stride; } return 0;}#if 0static int putvline (GAL_GC gc, int x, int y, int h, void* buf){ int i,k,x1,x2,y1,y2,ret,hh; unsigned char *dest; k = 0; getclipping(gc,&x1,&y1,&x2,&y2); hh = h; hh += y; ret = getclippingrect(x1,y1,x2,y2,&x,&y,&x,&hh); if ( ret == -1 ) return -1; hh -= y; for ( i = 0; i < hh; i++ ) { dest = gc.ads->fb_buf + (gc.ads->stride)*(y+i) + (gc.ads->stride)*x/MAX_X; *dest = ((unsigned char *)buf)[k++]; } return 0;}static int getvline (GAL_GC gc, int x, int y, int h, void* buf){ int i,k,x1,y1,x2,y2; unsigned char *dest; k = 0; getclipping(gc,&x1,&y1,&x2,&y2); for ( i = 0; i < min(h,y2-y1); i++ ) { dest = gc.ads->fb_buf+(gc.ads->stride)*(y+i)+(gc.ads->stride)*x/MAX_X; ((unsigned char *)buf)[k++] = *dest; } return 0;}#endif// Pixel operationsstatic int drawpixel (GAL_GC gc, int x, int y, gal_pixel pixel){ int x1,y1,x2,y2; unsigned char *dest; getclipping(gc,&x1,&y1,&x2,&y2); if ( x >= x1 && x <= x2 && y >= y1 && y <= y2 ) { dest = gc.ads->fb_buf+(gc.ads->stride)*y+(gc.ads->stride)*x/MAX_X; *dest = pixel; return 0; } return -1;}#if 0static int putpixel (GAL_GC gc, int x, int y, gal_pixel color){ int x1,y1,x2,y2; unsigned char *dest; getclipping(gc,&x1,&y1,&x2,&y2); if ( x >= x1 && x <= x2 && y >= y1 && y <= y2 ) { dest = gc.ads->fb_buf+(gc.ads->stride)*y+(gc.ads->stride)*x/MAX_X; *dest = color; return 0; } return -1;}#endifstatic int getpixel (GAL_GC gc, int x, int y, gal_pixel* color){ int x1,y1,x2,y2; unsigned char *dest; getclipping(gc,&x1,&y1,&x2,&y2); if ( x >= x1 && x <= x2 && y >= y1 && y <= y2 ) { dest = gc.ads->fb_buf+(gc.ads->stride)*y+(gc.ads->stride)*x/MAX_X; *color = *dest; return 0; } return -1;}// Other drawing// without any codestatic int circle (GAL_GC gc, int x, int y, int r, gal_pixel pixel){ return 0;}static int line (GAL_GC gc, int x1, int y1, int x2, int y2, gal_pixel pixel){ return 0;}static int rectangle (GAL_GC gc, int l, int t, int r, int b, gal_pixel pixel){ drawhline(gc,l,t,(r-l)+1,pixel); drawvline(gc,l,t,(b-t)+1,pixel); drawhline(gc,l,b,(r-l)+1,pixel); drawvline(gc,r,t,(b-t)+1,pixel); return 0;}static void panic (int exitcode){}BOOL InitADS (GFX* gfx){ int i; int fs; ads = (ADS *)malloc(sizeof(ads)); ads->bpp = 1; ads->depth = 8; ads->width = MAX_X; ads->height = MAX_Y; ads->bkcolor = 0; ads->fgcolor = 255; ads->r_mask = ((1<<2)-1)<<6; ads->g_mask = ((1<<3)-1)<<3; ads->b_mask = ((1<<3)-1); ads->r_map = calc_total(ads->r_mask) - 8; ads->g_map = calc_total(ads->g_mask) - 8; ads->b_map = calc_total(ads->b_mask) - 8; ads->stride = MAX_X / 8 * ads->depth; fs = open("/dev/fb0",O_RDWR); ads->fb_buf = mmap(0,MAX_Y*ads->stride,PROT_READ|PROT_WRITE,MAP_SHARED,fs,0); close(fs); for (i=0; i<17; i++) SysPixelIndex [i] = mapcolor (gfx->phygc, (GAL_Color *)(&SysPixelColor[i])); gfx->phygc.ads = ads; gfx->bytes_per_phypixel = ads->bpp; gfx->bits_per_phypixel = ads->depth; gfx->width_phygc = ads->width; gfx->height_phygc = ads->height; gfx->colors_phygc = 1 << ads->depth; gfx->grayscale_screen = FALSE; gfx->bytesperpixel = bytes_per_pixel; gfx->bitsperpixel = bits_per_pixel; gfx->width = width; gfx->height = height; gfx->colors = colors; gfx->allocategc = allocategc; gfx->freegc = freegc; gfx->setgc = NULL; gfx->enableclipping = enableclipping; gfx->disableclipping = disableclipping; gfx->setclipping = setclipping; gfx->getclipping = getclipping; gfx->getbgcolor = NULL; gfx->setbgcolor = NULL; gfx->getfgcolor = NULL; gfx->setfgcolor = NULL; gfx->mapcolor = mapcolor; gfx->unmappixel = unmappixel; gfx->getpalette = getpalette; gfx->setpalette = setpalette; gfx->setcolorfulpalette = setcolorfulpalette; gfx->boxsize = boxsize; gfx->fillbox = fillbox; gfx->putbox = putbox; gfx->getbox = getbox; gfx->putboxmask = putboxmask; gfx->scalebox = scalebox; gfx->copybox = copybox; gfx->crossblit = crossblit; gfx->drawhline = drawhline; gfx->drawvline = drawvline; gfx->drawpixel = drawpixel; gfx->getpixel = getpixel; gfx->circle = circle; gfx->line = line; gfx->rectangle = rectangle; gfx->panic = panic; return TRUE;}void TermADS (GFX* gfx){ munmap((void *)ads->fb_buf,MAX_Y*ads->stride); free(ads);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -