📄 libfbx-color.c
字号:
/* * libfbx-color.c -- Color making functions * (C)opyright 2000-2001 U4X Labs * * Written by: Mike Bourgeous <nitrogen@u4x.org> * Sat Sep 2 17:40:09 EDT 2000 * * Updated by: Paul Mundt <lethal@u4x.org> * Sat Dec 30 23:26:15 EST 2000 * * $Id: libfbx-color.c,v 1.8 2001/02/23 21:09:26 nitroglycerine Exp $ * * Originally part of fbgraph.c, now separate. Responsible * for creating colors and colormaps. * * 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>/* * Function: fb_make_color_8() * Arguments: rgb values (0-255) * Returns: 8-bit color * Description: Makes a color out of specified rgb values for * specified bit depth and returns it. */unsigned long fb_make_color_8(int r, int g, int b){ r >>= 5; g >>= 5; b >>= 6; r &= 7; g &= 7; b &= 3; return (r << 5 | g << 2 | b << 0);}/* * Function: fb_make_color_15() * Arguments: rgb values (0-255) * Returns: 15-bit color * Description: Makes a color out of specified rgb values for * specified bit depth and returns it. */unsigned long fb_make_color_15(int r, int g, int b){ r >>= 3; g >>= 3; b >>= 3; return (r << 10 | g << 5 | b);}/* * Function: fb_make_color_16() * Arguments: rgb values (0-255) * Returns: 16-bit color * Description: Makes a color out of specified rgb values for * specified bit depth and returns it. */unsigned long fb_make_color_16(int r, int g, int b){ r >>= 3; g >>= 2; b >>= 3; return (r << 11 | g << 5 | b);}/* * Function: fb_make_color_24() * Arguments: rgb values (0-255) * Returns: 24-bit color * Description: Makes a color out of specified rgb values for * specified bit depth and returns it. */unsigned long fb_make_color_24(int r, int g, int b){ r &= 0xFF; g &= 0xFF; b &= 0xFF; return (r << fb_screen->red_offset | g << fb_screen->green_offset | b << fb_screen->blue_offset);}/* * Function: fb_make_color_unknown() * Arguments: rgb values (0-255) * Returns: What is hopefully the color * Description: Tries to figure out how to make a color for * an unknown bit depth. */unsigned long fb_make_color_unknown(int r, int g, int b){ r &= 0xFF; g &= 0xFF; b &= 0xFF; r <<= fb_screen->red_size - 8; g <<= fb_screen->green_size - 8; b <<= fb_screen->blue_size - 8; r &= 0xFF << (fb_screen->red_size - 8); g &= 0xFF << (fb_screen->green_size - 8); b &= 0xFF << (fb_screen->blue_size - 8); return (r << fb_screen->red_offset | g << fb_screen->green_offset | b << fb_screen->blue_offset);}/** Function: fb_get_color()* Arguments: Hardware color, pointers to location to store * color components* Returns: None* Description: Stores the color components of the given hardware* color in the given locations.*/void fb_get_color(unsigned int hwcolor, int *r, int *g, int *b){ *r = ((hwcolor >> fb_screen->red_offset) & ((1 << fb_screen->red_size) - 1)) >> (fb_screen->red_size - 8); *g = ((hwcolor >> fb_screen->green_offset) & ((1 << fb_screen->green_size) - 1)) >> (fb_screen->green_size - 8); *b = ((hwcolor >> fb_screen->blue_offset) & ((1 << fb_screen->blue_size) - 1)) >> (fb_screen->blue_size - 8);}/* * Function: fb_make_332_map() * Arguments: pointer to fb colormap struct * Returns: None * Description: This function generates a color map for use * in 8-bit color modes. It is a simulated * truecolor palette. */void fb_make_332_map(struct fb_cmap *map){ int rs, gs, bs, i; int r = 8, g = 8, b = 4; map->red = red; map->green = green; map->blue = blue; rs = 256 / (r - 1); gs = 256 / (g - 1); bs = 256 / (b - 1); for (i = 0; i < 256; i++) { map->red[i] = (rs * ((i / (g * b)) % r)) * 255; map->green[i] = (gs * ((i / b) % g)) * 255; map->blue[i] = (bs * ((i) % b)) * 255; }}/* * Function: fb_get_textcolor() * Arguments: Pointers to foreground and background to * place values in. * Returns: None. * Description: Places current foreground and background * colors in specified variables. */void fb_get_textcolor(int *fg, int *bg){ *fg = fb_screen->text.color; *bg = fb_screen->text.bgcolor;}/* * Function: fb_sget_textcolor() * Arguments: Pointers to surface to get values from * and pointers to foreground and background to * place values in. * Returns: None. * Description: Places current foreground and background * colors in specified variables. */void fb_sget_textcolor(fb_surface *surface, int *fg, int *bg){ *fg = surface->text.color; *bg = surface->text.bgcolor;}/* * Function: fb_set_textcolor() * Arguments: Foreground and background values. * Returns: None. * Description: Sets the text color to the specified * foreground and background values. */void fb_set_textcolor(int fg, int bg){ fb_screen->text.color = fg; fb_screen->text.bgcolor = bg;}/* * Function: fb_sset_textcolor() * Arguments: Surface, foreground and background values. * Returns: None. * Description: Sets the text color to the specified * foreground and background values. */void fb_sset_textcolor(fb_surface *surface, int fg, int bg){ surface->text.color = fg; surface->text.bgcolor = bg;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -