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

📄 libfbx-blit.c

📁 libfxb是linux下只写操作framebuffer的一个轻量级的库。
💻 C
字号:
/* *  libfbx-blit.c -- Surface Blit Functions *  (C)opyright 2000-2001 U4X Labs * *  Written by: Mike Bourgeous <nitrogen@u4x.org> *              Sat Sep 2 13:41:50 EDT 2000 * *  $Id: libfbx-blit.c,v 1.23 2001/02/05 06:12:14 lethal Exp $ * *       Originally part of fbgraph.c, now separate.  Responsible for *  drawing surfaces onto one another. * *  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 <libfbx/libfbx.h>#include <libfbx/libfbx-drivers.h>/* * Function:	fb_draw_image() * Arguments:	source and destination surface, x and y positioners * Returns:	None * Description:	Draws a surface to another surface. */void fb_draw_image(fb_surface *src, 		   fb_surface *dest, 		   int x, int y){	int xpos = x, ypos = y;	int xtmp = x, ytmp = y;	int r, g, b;	register unsigned char *ptr1, *ptr2;	if (dest->driver != NULL && dest->driver->ops->has_draw_image) {	    	dest->driver->ops->draw_image(src, dest, x, y);		return;	}	ptr1 = (unsigned char *)(src->mem_pointer + 				 src->mem_offset + 				 ypos * src->line_size + 				 xpos * src->pixel_size);	ptr2 = (unsigned char *)(dest->mem_pointer +				 dest->mem_offset +				 (ypos - y) * dest->line_size);	/*	if (src->width == dest->width &&             src->height <= dest->height &&             src->bpp == dest->bpp && x == 0 && y == 0)		fb_memmove(ptr2, ptr1, src->width * src->height * src->pixel_size);	*/	if (x <= -src->width || y <= -src->height || x > dest->width || y > dest->height)		return;		if (src->bpp == dest->bpp /*&& 	    strncmp(src->driver->id, "VESA VGA", 32) != 0 && 	    strncmp(dest->driver->id, "VESA VGA", 32) != 0*/)		if(x < 0 || y < 0)		{			xtmp = MAX(0, -x);			ytmp = MAX(0, -y);			for (ypos = y; ypos < y + src->height &&         	             ypos < dest->height; ypos++)			{				if(ypos < 0)					continue;								ptr1 = (unsigned char *)(src->mem_pointer + 					                 src->mem_offset +  							 (ypos - y) * src->line_size + 							 xtmp * src->pixel_size);				ptr2 = (unsigned char *)(dest->mem_pointer +							 dest->mem_offset +							 ypos * dest->line_size +							 (xpos + xtmp) * dest->pixel_size);	 			fb_memmove(ptr2, ptr1, MIN((src->width - xtmp) * src->pixel_size, 						   (dest->width - x) * 						   dest->pixel_size));			}		}		else			for (ypos = y; ypos < y + src->height &&			     ypos < dest->height; ypos++)			{				ptr1 = (unsigned char *)(src->mem_pointer + 					                 src->mem_offset +							 (ypos - y) * src->line_size);				ptr2 = (unsigned char *)(dest->mem_pointer +							 dest->mem_offset +							(ypos) * dest->line_size +							 xpos * dest->pixel_size);	 			fb_memmove(ptr2, ptr1, MIN(src->width * src->pixel_size, 						   (dest->width - x) * 						   dest->pixel_size));			}	else		for (ypos = y; ypos < y + src->height &&                                ypos < dest->height; ypos++)			for(xpos = x; xpos < x + src->width &&                                       xpos < dest->width; xpos++) {				fb_getpixel(xpos - x, ypos - y, 					    &r, &g, &b, src);				fb_putpixel(xpos, ypos, r, g, b, dest);			}}/* * Function:	fb_draw_masked_image() * Arguments:	source, destination, (x, y) coordinates * Returns:	None * Description:	Displays an image at the specified coordinates on  * 		the destination surface, skipping over the color * 		magenta (255, 0, 255), and stopping at w, h. */void fb_draw_masked_image(fb_surface *src, fb_surface *dest, int x, int y, int w, int h){	int xpos = x, ypos = y;	int r, g, b;	int mr = 255, mg = 0, mb = 255;	fb_surface *check;		/* I'll admit, this is kind of ugly */	check = fb_create_surface(1, 1);	fb_putpixel(0, 0, 255, 0, 255, check);	fb_getpixel(0, 0, &mr, &mg, &mb, check);	for (ypos = y; ypos < y + src->height && 	     ypos < dest->height && ypos < y + h; ypos++)		for(xpos = x; xpos < x + src->width && 		    xpos < dest->width && xpos < x + w; xpos++) {			fb_getpixel(xpos - x, ypos - y, 				    &r, &g, &b, src);			if(r != mr || g != mg || b != mb)				fb_putpixel(xpos, ypos, r, g, b, dest);		}	fb_destroy_surface(check);}/* * Function:	fb_put_linux_logo() * Arguments:	x, y positioners, width and height of image, *              image data, rgb colormap values, and destination *              surface. * Returns:	None * Description: Displays a linux_logo.h image to destination * 		surface at specified x, y position. */void fb_put_linux_logo(int xpos, int ypos, 			      int width, int height, 			      unsigned char data[], 			      unsigned char red_map[], 			      unsigned char green_map[], 			      unsigned char blue_map[],			      fb_surface *destination){	int x, y, pos = 0;	for (y = ypos; (y < (height + ypos)) &&                        (y < destination->height); y++)		for (x = xpos; (x < (width + xpos)) &&                                (y < destination->width); x++) {			pos = y * width + x;			fb_putpixel(x, y, red_map[data[pos] - 0x20],                                           green_map[data[pos] - 0x20],                                           blue_map[data[pos] - 0x20],                                           destination);		}}

⌨️ 快捷键说明

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