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

📄 libfbx-surface.c

📁 libfxb是linux下只写操作framebuffer的一个轻量级的库。
💻 C
字号:
/* *  libfbx-surface.c -- Surface Handling Functions *  (C)opyright 2000-2001 U4X Labs * *  Written by: Mike Bourgeous <nitrogen@u4x.org> *              Sun Sep 3 14:04:44 EDT 2000 * *  $Id: libfbx-surface.c,v 1.19 2001/02/23 21:09:26 nitroglycerine Exp $ * *       Originally part of fbgraph.c, now separate.  These functions *  handle creation and destruction of surfaces. * *  See ChangeLog for modifications, CREDITS for credits. *  			 *  All source herein is copyright U4X Labs and its original author.  *  Any code modifications or additions are (C)opyright the original  *  author and U4X Labs respectively. * *  libfbx is free software; you can redistribute it and/or modify it  *  under the terms of the GNU Lesser General Public License as  *  published by the Free Software Foundation; either version 2.1 of  *  the License, or (at your option) any later version. * *  libfbx 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 Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with libfbx; if not, write to the Free Software  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *  USA */#include <stdio.h>#include <errno.h>#include <fcntl.h>#include <unistd.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <signal.h>#include <time.h>#include <math.h>#include <linux/fb.h>#include <linux/kd.h>#include <sys/mman.h>#include <sys/ioctl.h>#include <sys/user.h>#include <termios.h>#include <ctype.h>#include <libfbx/libfbx.h>#include <libfbx/libfbx-drivers.h>#include <linux/types.h>/*  * Function:	fb_create_surface() * Arguments:	width and height of surface * Returns:	A pointer to the newly created surface * Description:	Creates a new fb_surface in system memory  * 		with the specified width and height. */fb_surface *fb_create_surface(int width, int height){	return fb_create_surface_depth(width, height, fb_screen->bpp);}/* * Function:	fb_create_surface_depth()* Arguments:	width, height, and color depth of surface* Returns:	A pointer to the newly created surface* Description:	Creates a new fb_surface in system memory * 		with the specified width, height, and depth.*/fb_surface *fb_create_surface_depth(int width, int height, int depth){	char *new_bitmap = malloc(width * height * fb_screen->pixel_size);	fb_surface *new_surface = malloc(sizeof(fb_surface));	int d = 0;	int s = 0;	int rl = 0, ro = 0;	int gl = 0, go = 0;	int bl = 0, bo = 0;	unsigned long (*make_color)(int r, int g, int b);		switch(depth) {		case 8:			d = 8;			s = 1;			rl = 3;			gl = 3;			bl = 2;			ro = 5;			go = 2;			bo = 0;			make_color = fb_make_color_8;			break;		case 15:			d = 15;			s = 2;			rl = 5;			gl = 5;			bl = 5;			ro = 10;			go = 5;			bo = 0;			make_color = fb_make_color_15;			break;		case 16:			d = 16;			s = 2;			rl = 5;			gl = 6;			bl = 5;			ro = 11;			go = 5;			bo = 0;			make_color = fb_make_color_16;			break;		case 24:			d = 24;			s = 3;			rl = 8;			gl = 8;			bl = 8;			ro = 16;			go = 8;			bo = 0;			make_color = fb_make_color_24;			break;		case 32:			d = 32;			s = 4;			rl = 8;			gl = 8;			bl = 8;			ro = 16;			go = 8;			bo = 0;			make_color = fb_make_color_24;			break;		default:			/* Unsupported depth */			return NULL;	}		if (new_surface != NULL && new_bitmap != NULL) {		new_surface->finfo        = calloc(1, sizeof(struct fb_fix_screeninfo));		new_surface->vinfo        = calloc(1, sizeof(struct fb_var_screeninfo));		new_surface->vinfo->xres  = width;		new_surface->vinfo->yres  = height;		new_surface->width        = width;		new_surface->height       = height;		new_surface->pixel_size   = s;		new_surface->bpp          = d;		new_surface->line_size    = width * s;		new_surface->buffer_size  = width * height * s;		new_surface->mem_offset   = 0;		new_surface->mem_pointer  = new_bitmap;		new_surface->make_color   = make_color;		new_surface->red_size     = rl;		new_surface->red_offset   = ro;		new_surface->green_size   = gl;		new_surface->green_offset = go;		new_surface->blue_size    = bl;		new_surface->blue_offset  = bo;		new_surface->driver	  = calloc(1, sizeof(fb_driver));		new_surface->driver->ops  = calloc(1, sizeof(fb_driver_ops));		new_surface->text.color   = make_color(255, 255, 255);		new_surface->text.mask	  = FALSE;		new_surface->font	  = fb_screen->font;		strcpy(new_surface->driver->id, "Memory");	}	return new_surface;}/* * Function:	fb_destroy_surface() * Arguments:	Pointer to surface * Returns:	None * Description:	Destroys a created fb_surface when it is * 		no longer needed.  Do not pass a screen * 		bitmap to this function. */void fb_destroy_surface(fb_surface *surface){	if (surface != NULL) {		if (surface->mem_pointer != NULL)			free(surface->mem_pointer);		if (surface->finfo != NULL)			cfree(surface->finfo);		if (surface->vinfo != NULL)			cfree(surface->vinfo);		if (surface->driver->ops != NULL)			cfree(surface->driver->ops);		if (surface->driver != NULL)			cfree(surface->driver);		free(surface);	}}/* * Function:    fb_scls() * Arguments:	Pointer to surface * Returns:     None * Description: Clears the specified surface */inline void fb_scls(fb_surface *surface){		if (surface != NULL && surface->mem_pointer != NULL)		fb_memset((void *)(surface->mem_pointer + 				   surface->mem_offset), 				   0, surface->buffer_size);	/*	char *pos = (char *)(surface->mem_pointer + surface->mem_offset);	int i;	for(i = 0; i < surface->buffer_size; i++)	{		*pos = 0;		pos++;	}	*/}/*  * Function:	fb_cls() * Arguments:	None * Returns:	None * Description:	Clears the screen */inline void fb_cls(){	fb_scls(fb_screen);}

⌨️ 快捷键说明

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