📄 ep7211.c
字号:
//// $Id: ep7211.c,v 1.10 2002/01/15 06:09:30 ymwei Exp $//// ep7211.c: Low Level Graphics Engine for ARM EP7211//// This is customized graphics engine for an embedded system // which based on Curris Logic EP7211.//// NOTE: you should use the new native GAL engine for the EP7211 systems.///*** This library is free software; you can redistribute it and/or** modify it under the terms of the GNU Library General Public** License as published by the Free Software Foundation; either** version 2 of the License, or (at your option) any later version.**** This library is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU** Library General Public License for more details.**** You should have received a copy of the GNU Library General Public** License along with this library; if not, write to the Free** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,** MA 02111-1307, USA*/// Modify records://// Who When Where For What Status//-----------------------------------------------------------------------------////#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/mman.h>#include <linux/fb.h>#include "common.h"#include "gal.h"#include "ep7211.h"static VIS_EP7211 *vis_ep7211;static int MAX_X,MAX_Y;static int getclippingrect (int sx1,int sy1,int sx2,int sy2,int *dx1,int *dy1,int *dx2,int *dy2){ *dx1 = ((*dx1) > sx1) ? (*dx1) : sx1; *dy1 = ((*dy1) > sy1) ? (*dy1) : sy1; *dx2 = ((*dx2) < sx2) ? (*dx2) : sx2; *dy2 = ((*dy2) < sy2) ? (*dy2) : sy2; if ( *dx1 >= *dx2 || *dy1 >= *dy2 ) { return FALSE; } return TRUE;}// GC propertiesstatic int bytes_per_pixel (GAL_GC gc){ return gc.vis_ep7211->bpp;}static int bits_per_pixel (GAL_GC gc){ return gc.vis_ep7211->depth;}static int width (GAL_GC gc){ return gc.vis_ep7211->width;}static int height (GAL_GC gc){ return gc.vis_ep7211->height;}static int colors (GAL_GC gc){ int depth = bits_per_pixel (gc); return 1 << depth;}// Allocation and release of graphics contextstatic int allocategc (GAL_GC gc, int width, int height, int depth, GAL_GC* newgc){ newgc->vis_ep7211 = (VIS_EP7211 *)malloc(sizeof(VIS_EP7211)); if ( newgc->vis_ep7211 == NULL ) return -1; newgc->vis_ep7211->bpp = gc.vis_ep7211->bpp; newgc->vis_ep7211->bkcolor = gc.vis_ep7211->bkcolor; newgc->vis_ep7211->fgcolor = gc.vis_ep7211->fgcolor; newgc->vis_ep7211->x1 = gc.vis_ep7211->x1; newgc->vis_ep7211->y1 = gc.vis_ep7211->y1; newgc->vis_ep7211->x1 = gc.vis_ep7211->x1; newgc->vis_ep7211->y2 = gc.vis_ep7211->y2; newgc->vis_ep7211->shift = gc.vis_ep7211->shift; newgc->vis_ep7211->stride = gc.vis_ep7211->stride; newgc->vis_ep7211->fb_buf = gc.vis_ep7211->fb_buf; newgc->vis_ep7211->width = width; newgc->vis_ep7211->height = height; newgc->vis_ep7211->depth = depth; return 0;}// without any codestatic void freegc (GAL_GC gc){ free(gc.vis_ep7211); }// Clipping of graphics context// without any codestatic void enableclipping (GAL_GC gc){ gc.vis_ep7211->x1 = 0; gc.vis_ep7211->y1 = 0; gc.vis_ep7211->x2 = gc.vis_ep7211->width-1; gc.vis_ep7211->y2 = gc.vis_ep7211->height-1;}static void disableclipping (GAL_GC gc){ enableclipping(gc);}static int setclipping (GAL_GC gc, int x1, int y1, int x2, int y2){ // ggiSetGCClipping (gc.visual, x1, y1, x2 + 1, y2 + 1); gc.vis_ep7211->x1 = x1; gc.vis_ep7211->y1 = y1; gc.vis_ep7211->x2 = x2; gc.vis_ep7211->y2 = y2; return 0;}static int getclipping (GAL_GC gc, int* x1, int* y1, int* x2, int* y2){ *x1 = gc.vis_ep7211->x1; *y1 = gc.vis_ep7211->y1; *x2 = gc.vis_ep7211->x2; *y2 = gc.vis_ep7211->y2; return 0;}// Background and foreground colors/*static int getbgcolor (GAL_GC gc, gal_pixel* color){ *color = gc.vis_ep7211->bkcolor; return 0;}static int setbgcolor (GAL_GC gc, gal_pixel color){ gc.vis_ep7211->bkcolor = color; return 0;}static int getfgcolor (GAL_GC gc, gal_pixel* color){ *color = gc.vis_ep7211->fgcolor; return 0;}static int setfgcolor (GAL_GC gc, gal_pixel color){ gc.vis_ep7211->fgcolor = color; return 0;}*/static gal_pixel mapcolor(GAL_GC gc, GAL_Color *color){ gal_pixel ret; return ret = (color->r*82 + color->g*124 + color->b*50) >> gc.vis_ep7211->shift;}static int unmappixel (GAL_GC gc, gal_pixel pixel, GAL_Color* color){ color->r = color->g = color->b = (pixel << gc.vis_ep7211->shift) >> 8; return 0;}#if 0static int packcolors (GAL_GC gc, void* buf, GAL_Color* colors, int len){ int i; unsigned char *outbuf=(unsigned char *)buf; for (i = 0; i < len; i++) { *(outbuf++) = (colors[i].r*82 + colors[i].g*124 + colors[i].b*50) >> gc.vis_ep7211->shift; } return 0;}static int unpackpixels (GAL_GC gc, void* buf, GAL_Color* colors, int len){ int i; unsigned char *outbuf=(unsigned char *)buf; for (i = 0; i < len; i++) { colors[i].r = colors[i].g = colors[i].b = ( *(outbuf++) << gc.vis_ep7211->shift) >> 8; } return 0;}#endif// Palette operationsstatic int getpalette (GAL_GC gc, int s, int len, GAL_Color* cmap){ int i; for (i = 0; i < len; i++) { cmap [i].r = (((s + i)%16 + 1) << 4) - 1; cmap [i].g = (((s + i)%16 + 1) << 4) - 1; cmap [i].b = (((s + i)%16 + 1) << 4) - 1; } return 0;}static int setpalette (GAL_GC gc, int s, int len, GAL_Color* cmap){// int i;// for (i = 0; i < len; i++) {// cmap [i].r = rgb8to16 (cmap [i].r);// cmap [i].g = rgb8to16 (cmap [i].g);// cmap [i].b = rgb8to16 (cmap [i].b);// } // ggiSetPalette(gc.visual, s, len, (ggi_color *)cmap); return 0;}static int setcolorfulpalette (GAL_GC gc){// ggiSetColorfulPalette (gc.visual); return 0;}// Box operationsstatic size_t boxsize (GAL_GC gc, int w, int h){ return w * h * bytes_per_pixel (gc);}static int fillbox (GAL_GC gc, int x, int y, int w, int h, gal_pixel pixel){ int i,j,x1,y1,x2,y2,ret,ww,hh; unsigned char *dest; int shift; shift = gc.vis_ep7211->depth; getclipping(gc,&x1,&y1,&x2,&y2); ww = w; hh = h; ww += x; hh += y; ret = getclippingrect(x1,y1,x2,y2,&x,&y,&ww,&hh); if ( ret == -1 ) return -1; ww -= x; hh -= y; for (i = 0; i < hh; i++) { for (j =0; j < ww ; j++) { dest = gc.vis_ep7211->fb_buf + (gc.vis_ep7211->stride)*(MAX_Y-y-i) - (gc.vis_ep7211->stride)*(x+j)/MAX_X -1; if ( (x+j) % (8/shift) == 1 ) { *dest &= 0xff << shift; pixel &= 0xff >> (8-shift); *dest |= pixel; } else if ( (x+j) % (8/shift) == 0 ) { *dest &= 0xff >> (8-shift); pixel &= 0xff >> (8-shift); *dest |= pixel << shift; } } } return 0;}static int putbox (GAL_GC gc, int x, int y, int w, int h, void* buf){ int i,j,k,x1,x2,y1,y2,ret,xx,yy,ww,hh; unsigned char *dest; int shift; k = 0; shift = gc.vis_ep7211->depth; getclipping(gc,&x1,&y1,&x2,&y2); ww = w; hh = h; xx = x; yy = y; ww += x; hh += y; ret = getclippingrect(x1,y1,x2,y2,&xx,&yy,&ww,&hh); if ( ret == -1 ) return -1; ww -= xx; hh -= yy; for ( i = 0; i < h; i++ ) { if ((y+i >= yy) && (y+i <= yy+hh)) { for ( j = 0; j < w; j++ ) { if ( (x+j>=xx)&&(x+j<=xx+ww)) { dest = gc.vis_ep7211->fb_buf + (gc.vis_ep7211->stride)*(MAX_Y-y-i) - (gc.vis_ep7211->stride)*(x+j)/MAX_X -1; if ( (x+j) % (8/shift) == 1 ) { *dest &= 0xff << shift; ((unsigned char *)buf)[k] &= 0xff >> (8-shift); *dest |= ((unsigned char *)buf)[k]; } else if ( (x+j) % (8/shift) == 0 ) { *dest &= 0xff >> (8-shift); ((unsigned char *)buf)[k] &= 0xff >> (8-shift); *dest |= ((unsigned char *)buf)[k] << shift; } } k++; } } else k += w; } return 0;}static int getbox (GAL_GC gc, int x, int y, int w, int h, void* buf){ int i,j,k,x1,y1,x2,y2; unsigned char *dest; int shift; k = 0; shift = gc.vis_ep7211->depth; getclipping(gc,&x1,&y1,&x2,&y2); for ( i = 0; i < h; i++ ) { if ( y+i <= y2 && y+i >= y1 ) { for ( j = 0; j < w; j++ ) { if ( x+j <= x2 && x+j >= x1) { dest = gc.vis_ep7211->fb_buf+(gc.vis_ep7211->stride)*(MAX_Y-y-i)-(gc.vis_ep7211->stride)*(x+j)/MAX_X-1; if ( (x+j) % (8/shift) == 1 ) ((unsigned char *)buf)[k] = (0xff >> (8-shift)) & (*dest); else if ( (x+j) % (8/shift) == 0 ) ((unsigned char *)buf)[k] = *dest >> (8-shift); } k++; } } else k += w; } return 0;}static int putboxmask (GAL_GC gc, int x, int y, int w, int h, void* buf, gal_pixel transparent){ return 0;}/****************************************************************************//* scalebox comes from SVGALib, Copyright 1993 Harm Hanemaayer */typedef unsigned char uchar;/* We use the 32-bit to 64-bit multiply and 64-bit to 32-bit divide of the *//* 386 (which gcc doesn't know well enough) to efficiently perform integer *//* scaling without having to worry about overflows. */static inline int muldiv64 (int m1, int m2, int d){ long long int mul = (long long int) m1 * m2; return (int) (mul / d);}/* This is a DDA-based algorithm. *//* Iteration over target bitmap. */int scalebox (GAL_GC gc, int w1, int h1, void *_dp1, int w2, int h2, void *_dp2){ uchar *dp1 = _dp1; uchar *dp2 = _dp2; int xfactor; int yfactor; if (w2 == 0 || h2 == 0) return 0; xfactor = muldiv64(w1, 65536, w2); /* scaled by 65536 */ yfactor = muldiv64(h1, 65536, h2); /* scaled by 65536 */ switch (bytes_per_pixel (gc)) { case 1: { int y, sy; sy = 0; for (y = 0; y < h2;) { int sx = 0; uchar *dp2old = dp2; int x; x = 0; while (x < w2 - 8) { *(dp2 + x) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 1) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 2) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 3) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 4) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 5) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 6) = *(dp1 + (sx >> 16)); sx += xfactor; *(dp2 + x + 7) = *(dp1 + (sx >> 16)); sx += xfactor; x += 8; } while (x < w2) { *(dp2 + x) = *(dp1 + (sx >> 16)); sx += xfactor; x++; } dp2 += w2; 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; } } 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -