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

📄 accel.c

📁 linux 下svgalib编的一个界面程序示例
💻 C
📖 第 1 页 / 共 3 页
字号:
{	unsigned char bit = 0x80, res = 0;	for (; c; c >>= 1, bit >>= 1)	    if (c & 1)		res |= bit;	return res;}void DrawDots(void){    int i, n;    /* Fill the screen with random dots. */    gl_clearscreen(0);    n = WIDTH * HEIGHT / 100;	/* 1% filled. */    for (i = 0; i < n; i++)	gl_setpixel(rand() % WIDTH, rand() % HEIGHT, rand() % COLORS);}void DoAccelTest(void (*accelfunc) (void), char *name, int exp_pixelrate,		 int pixels_per_call){    int i, n, startclock, diffclock;    int rate, byterate;    if (exp_pixelrate < 0)	/* Special case, #iterations indicated. */	n = -exp_pixelrate;    else	/* Aim for about 5 seconds. */	n = exp_pixelrate * 5 / pixels_per_call + 1;    if (background_blits)	vga_accel(ACCEL_SETMODE, BLITS_IN_BACKGROUND);    startclock = clock();    for (i = 0; i < n; i++)	(*accelfunc) ();    if (background_blits)	vga_accel(ACCEL_SYNC);    diffclock = clock() - startclock;    if (diffclock == 0) {	/* At least let the program continue if something strange happens */	printf("%s: Timing Error",name);    } else {	rate = (long long) n *pixels_per_call * 100 / diffclock;	byterate = rate * BYTESPERPIXEL;	printf("%s: %ld.%ld Mpixels/s (%ld.%ld Mbytes/s)\n", name,	   rate / 1000000L, (rate % 1000000L) / 100000L,	   byterate / 1000000L, (byterate % 1000000L) / 100000L);    }}void FillBoxTest(void){    int i;    for (i = 0; i < 256; i++) {	vga_accel(ACCEL_SETFGCOLOR, i);	vga_accel(ACCEL_FILLBOX, 0, 0, WIDTH, HEIGHT);    }}void ScreenCopyTest(void){    /* Copy first 1/3 to second 1/3. */    vga_accel(ACCEL_SCREENCOPY, 0, 0, 0, HEIGHT / 3, WIDTH, HEIGHT / 3);    /* Copy third 1/3 to first 1/3. */    vga_accel(ACCEL_SCREENCOPY, 0, (HEIGHT / 3) * 2, 0, 0,	      WIDTH, HEIGHT / 3);    /* Copy second 1/3 to third 1/3. */    vga_accel(ACCEL_SCREENCOPY, 0, HEIGHT / 3, 0, (HEIGHT / 3) * 2,	      WIDTH, HEIGHT / 3);}void ScrollTest(void){    int i;    /*     * First write the line that will be scrolled into the screen,     * located after the visible screen.     */    /* Clear the line. */    vga_accel(ACCEL_SETFGCOLOR, 0);    vga_accel(ACCEL_FILLBOX, 0, HEIGHT, WIDTH, 1);    if (background_blits)	vga_accel(ACCEL_SYNC);    /* Write some new dots. */    for (i = 0; i < WIDTH / 100; i++)	gl_setpixel(rand() % WIDTH, HEIGHT, rand() % COLORS);    /* Scroll. */    vga_accel(ACCEL_SCREENCOPY, 0, 1, 0, 0,	      WIDTH, HEIGHT);}void FillBoxXORTest(void){    vga_accel(ACCEL_SETRASTEROP, ROP_XOR);    vga_accel(ACCEL_SYNC);    FillBoxTest();    vga_accel(ACCEL_SETRASTEROP, ROP_COPY);}void PutBitmapTest(void){    vga_accel(ACCEL_SETBGCOLOR, 0);    vga_accel(ACCEL_SETFGCOLOR, gl_rgbcolor(255, 0, 0));    vga_accel(ACCEL_PUTBITMAP, 0, 0, WIDTH, HEIGHT, bitmap);    vga_accel(ACCEL_SETFGCOLOR, gl_rgbcolor(0, 0, 255));    vga_accel(ACCEL_PUTBITMAP, 0, 0, WIDTH, HEIGHT, bitmap);}void DrawCross(int x, int y, int color) {    int i;    for(i = y - CROSS_SZ; i <= y + CROSS_SZ; i++)	if (y != i)	    gl_setpixel(x, i, color);    for(i = x - CROSS_SZ; i <= x + CROSS_SZ; i++)	gl_setpixel(i, y, color);}void GetLogo(void) {    FILE *fd;    fd = fopen(LOGO_NAME, "rb");    if (!fd) {      read_err:	perror("Problems reading linuxlogo.bmp");	exit(2);    }    if (1 != fread(blitimage, LOGO_WIDTH * LOGO_HEIGHT, 1, fd))	goto read_err;    fclose(fd);}void ScaleLogo(void) {    unsigned char *ptr;    int w, h, x, y;    expandimage = malloc(LOGO_WIDTH * LOGO_HEIGHT * BYTESPERPIXEL);    w = BOXES_WIDTH - 2 * BOXES_B - 2;    h = BOXES_HEIGHT - 2 * BOXES_B - 2;    scaleimage = malloc(w * h * BYTESPERPIXEL);    if (!scaleimage || !expandimage) {	perror("Out of buffer memory");	exit(2);    }    gl_setcontextvirtual(LOGO_WIDTH, LOGO_HEIGHT, BYTESPERPIXEL, BITSPERPIXEL, expandimage);    for(y = 0, ptr = blitimage; y < LOGO_HEIGHT; y++)	for(x = 0; x < LOGO_WIDTH; x++, ptr++) {	    gl_setpixelrgb(x, y, (7 & *ptr) << 5, (7 & (*ptr >> 3)) << 5,			   (3 & (*ptr >> 6)) << 6);    }    gl_scalebox(LOGO_WIDTH, LOGO_HEIGHT, expandimage, w, h, scaleimage);}void DrawFrame(int x1, int y1, int x2, int y2, int color) {    DrawCross(x1, y1, color);    DrawCross(x2, y1, color);    DrawCross(x1, y2, color);    DrawCross(x2, y2, color);}void DrawHlines(int x, int y, int w, int h) {    int i, *xmin, *xmax;    xmin = alloca(sizeof(int) * h);    xmax = alloca(sizeof(int) * h);    for(i = 0; i < h; i++)	xmin[i] = x + (i * w  - i + (h >> 2)) / (h - 1);    x += w - 1;    for(i = 0; i < h; xmax[i++] = x);    vga_accel(ACCEL_DRAWHLINELIST, y, h, xmin, xmax);}void HlineBoxTest(void) {    int i, *xmin, *xmax;    xmin = alloca(sizeof(int) * HEIGHT);    xmax = alloca(sizeof(int) * HEIGHT);    memset(xmin, 0, sizeof(int) * HEIGHT);    for(i = 0; i < HEIGHT; xmax[i++] = WIDTH - 1);    for (i = 0; i < 256; i++) {	vga_accel(ACCEL_SETFGCOLOR, i);	vga_accel(ACCEL_DRAWHLINELIST, 0, HEIGHT, xmin, xmax);    }}static void draw_poly(unsigned short *coords) {    /* Intended bug: */    vga_accel(ACCEL_POLYLINE, ACCEL_START | ACCEL_END, 2, coords);    vga_accel(ACCEL_POLYLINE, ACCEL_START, 2, coords + 2);    /* Proper continuation: */    vga_accel(ACCEL_POLYLINE, 0, 7, coords + 4);}static void draw_polyhli(int x, int y, int w, int h) {    int n, i, j, dp, flag = ACCEL_START;    unsigned short coords[40];    vga_lockvc();    for(i = 0; i < h;) {	for(j = n = dp = 0; (j < 3) && (i < h); j++, i++) {	    n++;	    if (i < (h >> 1)) {		coords[dp++] = 6;		coords[dp++] = x;		coords[dp++] = x + (((w / 4) * (h - i)) / h);		coords[dp++] = x + (w / 2) - (((w / 6) * ((h >> 1) - i)) / h);		coords[dp++] = x + (w / 2) + (((w / 6) * ((h >> 1) - i)) / h);		coords[dp++] = x + w - 1 - (((w / 4) * (h - i)) / h);		coords[dp++] = x + w - 1;	    } else {		coords[dp++] = 8;		coords[dp++] = x;		coords[dp++] = x + (((w / 4) * (h - i)) / h);		coords[dp++] = x + ((3 * w) / 8) - (((w / 6) * (i - (h >> 1))) / h);		coords[dp++] = x + ((3 * w) / 8) + (((w / 6) * (i - (h >> 1))) / h);		coords[dp++] = x + ((5 * w) / 8) - (((w / 6) * (i - (h >> 1))) / h);		coords[dp++] = x + ((5 * w) / 8) + (((w / 6) * (i - (h >> 1))) / h);		coords[dp++] = x + w - 1 - (((w / 4) * (h - i)) / h);		coords[dp++] = x + w - 1;	    }	}	if (n)	    vga_accel(ACCEL_POLYHLINE, flag | ((i >= h) ? ACCEL_END : 0), y, n, coords);	flag = 0;    }    vga_unlockvc();}static void draw_polygon(int mode, int x, int y, int w, int h) {    const unsigned short W = x + w - 1, H = y + h - 1;    unsigned short coords[] = {	x, y, W, y, W, H, (x + W)/2, y,	x, H, W, (y + H)/2, (x + W)/2, H,	x, (y + H)/2, W, (y + H)/2, 	x, y};    if (mode) {	int i;	for(i = 0; i < (sizeof(coords) / sizeof(unsigned short) - 3); i += 2)	    if (coords[i + 1] != coords[i + 3])		vga_accel(ACCEL_DRAWLINE, coords[i], coords[i + 1], coords[i + 2], coords[i + 3]);    } else {	vga_accel(ACCEL_POLYLINE, ACCEL_START, sizeof(coords) / (2 * sizeof(unsigned short)),	    coords);    }}void PositionTest(void) {    int x, y, red, i = 0, w, h;    red = gl_rgbcolor(255, 0, 0);    w = BOXES_WIDTH - 2 * BOXES_B;    h = BOXES_HEIGHT - 2 * BOXES_B;    gl_write(0, 0, "Testing accelerator positioning:");    for(y = BOXES_B + 8; y < HEIGHT; y += BOXES_HEIGHT)	for(x = BOXES_B; x < WIDTH; x += BOXES_WIDTH) {	    DrawFrame(x, y, x + w - 1, y + h - 1, red);	    switch(i++) {		case 0:		    if (accelfuncs & ACCELFLAG_FILLBOX) {			gl_write(x + 1, y + h + 3, "Fillbox");			vga_accel(ACCEL_SETFGCOLOR, gl_rgbcolor(0, 255, 0));			vga_accel(ACCEL_FILLBOX, x + 1, y + 1, w - 2, h - 2);		    }		    break;		case 1:		    if (accelfuncs & ACCELFLAG_DRAWLINE) {			gl_write(x + 1, y + h + 3, "Linedraw");			vga_accel(ACCEL_SETFGCOLOR, gl_rgbcolor(0, 255, 0));			vga_accel(ACCEL_DRAWLINE, x + 1, y + 1, x + w - 2, y + h - 2);			vga_accel(ACCEL_DRAWLINE, x + w - 2, y + 1, x + 1, y + h - 2);		    }		    break;		case 2:		    if (accelfuncs & ACCELFLAG_PUTIMAGE) {			gl_write(x + 1, y + h + 3, "Putimage");			vga_accel(ACCEL_PUTIMAGE, x + 1, y + 1, w - 2, h - 2, scaleimage);		    }		    break;		case 3:		    if (accelfuncs & ACCELFLAG_SCREENCOPY) {			gl_write(x + 1, y + h + 3, "Screencopy (l->h)");			gl_putbox(x + 1, y + 1, w - 2, h - 2, scaleimage); 			vga_accel(ACCEL_SCREENCOPY, x + 1, y + 1,				  x + COPY_OFF, y + COPY_OFF, w - 2, h - 2);			DrawFrame(x + COPY_OFF - 1, y + COPY_OFF - 1,				  x + COPY_OFF + w - 2, y + COPY_OFF + h - 2,				  gl_rgbcolor(0, 255, 0));		    }		    break;		case 4:		    if (accelfuncs & ACCELFLAG_SCREENCOPY) {			gl_write(x + 1, y + h + 3, "Screencopy (h->l)");			gl_putbox(x + 1, y + 1, w - 2, h - 2, scaleimage); 			vga_accel(ACCEL_SCREENCOPY, x + 1, y + 1,				  x - COPY_OFF, y - COPY_OFF, w - 2, h - 2);			DrawFrame(x - COPY_OFF - 1, y - COPY_OFF - 1,				  x - COPY_OFF + w - 2, y - COPY_OFF + h - 2,				  gl_rgbcolor(0, 255, 0));		    }		    break;		case 5:		    if (accelfuncs & ACCELFLAG_DRAWHLINELIST) {			gl_write(x + 1, y + h + 3, "Hlinelist");			vga_accel(ACCEL_SETFGCOLOR, gl_rgbcolor(0, 255, 0));			DrawHlines(x + 1, y + 1, w - 2, h - 2);		    }		    break;		case 6:		    if (accelfuncs & ACCELFLAG_PUTBITMAP) {			int xo, yo, i;			unsigned int bmaptmp[8];			gl_write(x + 1, y + h + 3, "PutBitmap");			vga_accel(ACCEL_SETBGCOLOR, gl_rgbcolor(255, 0, 0));			vga_accel(ACCEL_SETFGCOLOR, gl_rgbcolor(0, 255, 0));			for(i = 0; i < 8; i++)			    bmaptmp[i] = rotbyte(gl_font8x8['0' * 8 + i]);			vga_accel(ACCEL_PUTBITMAP, x + 1, y + 1,				8, 8, bmaptmp);			vga_accel(ACCEL_SETFGCOLOR, gl_rgbcolor(255, 0, 0));			vga_accel(ACCEL_SETBGCOLOR, gl_rgbcolor(0, 255, 0));			for(i = 0; i < 8; i++)			    bmaptmp[i] = rotbyte(gl_font8x8['1' * 8 + i]);			vga_accel(ACCEL_PUTBITMAP, x + w - 9, y + 1,				8, 8, bmaptmp);			vga_accel(ACCEL_SETFGCOLOR, gl_rgbcolor(0, 0, 0));			vga_accel(ACCEL_SETBGCOLOR, gl_rgbcolor(255, 255, 255));			for(i = 0; i < 8; i++)			    bmaptmp[i] = rotbyte(gl_font8x8['2' * 8 + i]);			vga_accel(ACCEL_PUTBITMAP, x + 1, y + h - 9,				8, 8, bmaptmp);			vga_accel(ACCEL_SETBGCOLOR, gl_rgbcolor(0, 0, 0));			vga_accel(ACCEL_SETFGCOLOR, gl_rgbcolor(255, 255, 255));

⌨️ 快捷键说明

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