Use libfbsplash and libfbsplashrender in TuxOnIce's userui. diff -Naurp suspend2-userui/fbsplash/cmd.c s2-userui-mod/fbsplash/cmd.c --- suspend2-userui/fbsplash/cmd.c 2007-07-26 17:55:58.000000000 +0200 +++ s2-userui-mod/fbsplash/cmd.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,113 +0,0 @@ -/* - * splash_cmd.c - Functions for handling communication with the kernel - * - * TuxOnIce userui adaptations: - * Copyright (C) 2005 Bernard Blackham - * - * Based on the original splashutils code: - * Copyright (C) 2004-2005 Michal Januszewski - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "splash.h" - -#ifdef CONFIG_FBSPLASH -#include - -void cmd_setstate(unsigned int state, unsigned char origin) -{ - struct fb_splash_iowrapper wrapper = { - .vc = arg_vc, - .origin = origin, - .data = &state, - }; - - if (fbsplash_fd == -1) - return; - - ioctl(fbsplash_fd, FBIOSPLASH_SETSTATE, &wrapper); -} - -void cmd_setpic(struct fb_image *img, unsigned char origin) -{ - struct fb_splash_iowrapper wrapper = { - .vc = arg_vc, - .origin = origin, - .data = img, - }; - - if (fbsplash_fd == -1) - return; - ioctl(fbsplash_fd, FBIOSPLASH_SETPIC, &wrapper); -} - -void cmd_setcfg(unsigned char origin) -{ - struct vc_splash vc_cfg; - struct fb_splash_iowrapper wrapper = { - .vc = arg_vc, - .origin = origin, - .data = &vc_cfg, - }; - - if (fbsplash_fd == -1) - return; - - vc_cfg.tx = cf.tx; - vc_cfg.ty = cf.ty; - vc_cfg.twidth = cf.tw; - vc_cfg.theight = cf.th; - vc_cfg.bg_color = cf.bg_color; - vc_cfg.theme = arg_theme; - - ioctl(fbsplash_fd, FBIOSPLASH_SETCFG, &wrapper); -} - -void cmd_getcfg() -{ - struct vc_splash vc_cfg; - struct fb_splash_iowrapper wrapper = { - .vc = arg_vc, - .origin = FB_SPLASH_IO_ORIG_USER, - .data = &vc_cfg, - }; - - vc_cfg.theme = malloc(FB_SPLASH_THEME_LEN); - if (!vc_cfg.theme) - return; - - if (ioctl(fbsplash_fd, FBIOSPLASH_GETCFG, &wrapper)) - printerr("FBIOSPLASH_GETCFG failed, error code %d.\n", errno); - if (vc_cfg.theme[0] == 0) { - strcpy(vc_cfg.theme, ""); - } - - printf("Splash config on console %d:\n", arg_vc); - printf("tx: %d\n", vc_cfg.tx); - printf("ty: %d\n", vc_cfg.ty); - printf("twidth: %d\n", vc_cfg.twidth); - printf("theight: %d\n", vc_cfg.theight); - printf("bg_color: %d\n", vc_cfg.bg_color); - printf("theme: %s\n", vc_cfg.theme); - - free(vc_cfg.theme); - return; -} - -#endif /* CONFIG_FBSPLASH */ - diff -Naurp suspend2-userui/fbsplash/common.c s2-userui-mod/fbsplash/common.c --- suspend2-userui/fbsplash/common.c 2007-07-26 17:55:58.000000000 +0200 +++ s2-userui-mod/fbsplash/common.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,290 +0,0 @@ -/* - * common.c - miscellaneous functions used by both the kernel helper and - * user utilities. - * - * TuxOnIce userui adaptations: - * Copyright (C) 2005 Bernard Blackham - * - * Based on the original splashutils code: - * Copyright (C) 2004-2005, Michal Januszewski - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "splash.h" - -struct fb_var_screeninfo fb_var; -struct fb_fix_screeninfo fb_fix; - -enum ENDIANESS endianess; -char *config_file = NULL; - -enum TASK arg_task = none; -int arg_fb = 0; -int arg_vc = 0; -char arg_mode = 'v'; -char *arg_theme = NULL; -u16 arg_progress = 0; -char *progress_text = NULL; -u8 arg_kdmode = KD_TEXT; - -#ifndef TARGET_KERNEL -char *arg_export = NULL; -#endif - -int bytespp = 4; /* bytes per pixel */ -u8 fb_opt = 0; /* can we use optimized 24/32bpp routines? */ -u8 fb_ro, fb_go, fb_bo; /* red, green, blue offset */ -u8 fb_rlen, fb_glen, fb_blen; /* red, green, blue length */ - -struct fb_image pic; -char *pic_file = NULL; - -void detect_endianess(void) -{ - u16 t = 0x1122; - - if (*(u8*)&t == 0x22) { - endianess = little; - } else { - endianess = big; - } - - DEBUG("This system is %s-endian.\n", (endianess == little) ? "little" : "big"); -} - -int get_fb_settings(int fb_num) -{ - char fn[32]; - int fb; -#ifdef TARGET_KERNEL - char sys[128]; -#endif - - sprintf(fn, PATH_DEV "/fb/%d", fb_num); - fb = open(fn, O_WRONLY, 0); - - if (fb == -1) { - sprintf(fn, PATH_DEV "/fb%d", fb_num); - fb = open(fn, O_WRONLY, 0); - } - - if (fb == -1) { -#ifdef TARGET_KERNEL - sprintf(sys, PATH_SYS "/class/graphics/fb%d/dev", fb_num); - create_dev(fn, sys, 0x1); - fb = open(fn, O_WRONLY, 0); - if (fb == -1) - remove_dev(fn, 0x1); - if (fb == -1) -#endif - { - printerr("Failed to open " PATH_DEV "/fb%d or " PATH_DEV - "/fb%d for reading.\n", fb_num, fb_num); - return 1; - } - } - - if (ioctl(fb,FBIOGET_VSCREENINFO,&fb_var) == -1) { - printerr("Failed to get fb_var info.\n"); - return 2; - } - - if (ioctl(fb,FBIOGET_FSCREENINFO,&fb_fix) == -1) { - printerr("Failed to get fb_fix info.\n"); - return 3; - } - - close(fb); - -#ifdef TARGET_KERNEL - remove_dev(fn, 0x1); -#endif - bytespp = (fb_var.bits_per_pixel + 7) >> 3; - - /* Check if optimized code can be used. We use special optimizations for - * 24/32bpp modes in which all color components have a length of 8 bits. */ - if (bytespp < 3 || fb_var.blue.length != 8 || fb_var.green.length != 8 || fb_var.red.length != 8) { - fb_opt = 0; - - if (fb_fix.visual == FB_VISUAL_DIRECTCOLOR) { - fb_blen = fb_glen = fb_rlen = min(min(fb_var.red.length,fb_var.green.length),fb_var.blue.length); - } else { - fb_rlen = fb_var.red.length; - fb_glen = fb_var.green.length; - fb_blen = fb_var.blue.length; - } - } else { - fb_opt = 1; - - /* Compute component offsets (ie. indexes in an array of u8's) */ - fb_ro = (fb_var.red.offset >> 3); - fb_go = (fb_var.green.offset >> 3); - fb_bo = (fb_var.blue.offset >> 3); - - if (endianess == big) { - fb_ro = bytespp - 1 - fb_ro; - fb_go = bytespp - 1 - fb_go; - fb_bo = bytespp - 1 - fb_bo; - } - } - - return 0; -} - -char *get_filepath(char *path) -{ - char buf[512]; - - if (path[0] == '/') - return strdup(path); - - snprintf(buf, 512, "%s/%s/%s", THEME_DIR, arg_theme, path); - return strdup(buf); -} - -char *get_cfg_file(char *theme) -{ - char buf[512]; - - snprintf(buf, 512, "%s/%s/%dx%d.cfg", THEME_DIR, theme, fb_var.xres, fb_var.yres); - return strdup(buf); -} - -int do_getpic(unsigned char origin, unsigned char do_cmds, char mode) -{ - if (load_images(mode)) - return -1; - -#if (defined(CONFIG_TTF) && !defined(TARGET_KERNEL)) || (defined(CONFIG_TTF_KERNEL) && defined(TARGET_KERNEL)) - load_fonts(); -#endif - -#ifdef CONFIG_FBSPLASH - if (do_cmds) { - cmd_setpic(&verbose_img, origin); - free((u8*)verbose_img.data); - if (verbose_img.cmap.red); - free(verbose_img.cmap.red); - } -#endif - return 0; -} - -#ifdef CONFIG_FBSPLASH -int do_config(unsigned char origin) -{ - if (!config_file) { - printerr("No config file.\n"); - return -1; - } - - /* If the user specified invalid values for the text field - correct it. - * Also setup default values (text field coverting the whole screen). */ - if (cf.tx > fb_var.xres) - cf.tx = 0; - - if (cf.ty > fb_var.yres) - cf.ty = 0; - - if (cf.tw > fb_var.xres || cf.tw == 0) - cf.tw = fb_var.xres; - - if (cf.th > fb_var.yres || cf.th == 0) - cf.th = fb_var.yres; - - cmd_setcfg(origin); - return 0; -} -#endif - -void vt_cursor_disable(int fd) -{ - write(fd, "\e[?25l\e[?1c",11); -} - -void vt_cursor_enable(int fd) -{ - write(fd, "\e[?25h\e[?0c",11); -} - -int open_fb() -{ - char dev[32]; - int c; - - sprintf(dev, PATH_DEV "/fb%d", arg_fb); - if ((c = open(dev, O_RDWR)) == -1) { - sprintf(dev, PATH_DEV "/fb/%d", arg_fb); - if ((c = open(dev, O_RDWR)) == -1) { - printerr("Failed to open " PATH_DEV "/fb%d or " - PATH_DEV "/fb/%d.\n", arg_fb, arg_fb); - return -1; - } - } - - return c; -} - -int open_tty(int tty) -{ - char dev[32]; - int c; - - sprintf(dev, PATH_DEV "/tty%d", tty); - if ((c = open(dev, O_RDWR)) == -1) { - sprintf(dev, PATH_DEV "/vc/%d", tty); - if ((c = open(dev, O_RDWR)) == -1) { - printerr("Failed to open " PATH_DEV "/tty%d or " - PATH_DEV "/vc/%d\n", tty, tty); - return 0; - } - } - - return c; -} - -int tty_set_silent(int tty, int fd) -{ - struct termios w; - - tcgetattr(fd, &w); - w.c_lflag &= ~(ICANON|ECHO); - w.c_cc[VTIME] = 0; - w.c_cc[VMIN] = 1; - tcsetattr(fd, TCSANOW, &w); - vt_cursor_disable(fd); - ioctl(fd, VT_ACTIVATE, tty); - ioctl(fd, VT_WAITACTIVE, tty); - - return 0; -} - -int tty_unset_silent(int fd) -{ - struct termios w; - - tcgetattr(fd, &w); - w.c_lflag &= (ICANON|ECHO); - w.c_cc[VTIME] = 0; - w.c_cc[VMIN] = 1; - tcsetattr(fd, TCSANOW, &w); - vt_cursor_enable(fd); - - return 0; -} diff -Naurp suspend2-userui/fbsplash/config.h s2-userui-mod/fbsplash/config.h --- suspend2-userui/fbsplash/config.h 2006-08-11 01:49:27.000000000 +0200 +++ s2-userui-mod/fbsplash/config.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,7 +0,0 @@ -#define CONFIG_PNG -#define CONFIG_TTF -#define CONFIG_TTF_KERNEL -#define CONFIG_FBSPLASH -#define CONFIG_MNG -#define THEME_DIR "/etc/splash" -#define SPLASH_FIFO "/lib/splash/cache/.splash" diff -Naurp suspend2-userui/fbsplash/effects.c s2-userui-mod/fbsplash/effects.c --- suspend2-userui/fbsplash/effects.c 2007-07-26 17:55:58.000000000 +0200 +++ s2-userui-mod/fbsplash/effects.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,232 +0,0 @@ -/* - * effects.c - miscellaneous graphical effects for splashutils - * - * TuxOnIce userui adaptations: - * Copyright (C) 2005 Bernard Blackham - * - * Based on the original splashutils code: - * Copyright (C) 2004-2005, Michal Januszewski - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ - -#include -#include -#include -#include -#include -#include "splash.h" - -#define FADEIN_STEPS 128 -#define FADEIN_STEPS_DC 256 - -void put_img(u8 *dst, u8 *src) -{ - int y, i; - u8 *to = dst; - - i = fb_var.xres * bytespp; - - for (y = 0; y < fb_var.yres; y++) { - memcpy(to, src + i*y, i); - to += fb_fix.line_length; - } -} - -void fade_in_directcolor(u8 *dst, u8 *image, int fd) -{ - int len, i, step; - struct fb_cmap cmap; - - len = min(min(fb_var.red.length,fb_var.green.length),fb_var.blue.length); - - cmap.start = 0; - cmap.len = (1 << len); - cmap.transp = NULL; - cmap.red = malloc(2 * 256 * 3); - if (!cmap.red) - return; - - cmap.green = cmap.red + 256; - cmap.blue = cmap.green + 256; - - for (i = 0; i < cmap.len; i++) { - cmap.red[i] = cmap.green[i] = cmap.blue[i] = 0; - } - - ioctl(fd, FBIOPUTCMAP, &cmap); - put_img(dst, image); - - for (step = 1; step < FADEIN_STEPS_DC+1; step++) { - for (i = 0; i < cmap.len; i++) { - cmap.red[i] = cmap.green[i] = cmap.blue[i] = (0xffff * i * step)/((cmap.len-1)*FADEIN_STEPS_DC); - } - ioctl(fd, FBIOPUTCMAP, &cmap); - usleep(7500); - } -} - -void fade_in_truecolor(u8 *dst, u8 *image) -{ - int rlen, glen, blen; - int i, step, h, x, y; - u8 *t, *p, *pic; - int r, g, b, rt, gt, bt; - int rl8, gl8, bl8; - int clut[256][FADEIN_STEPS]; - - rlen = fb_var.red.length; - glen = fb_var.green.length; - blen = fb_var.blue.length; - - rl8 = 8 - rlen; - gl8 = 8 - glen; - bl8 = 8 - blen; - - t = malloc(fb_var.xres * fb_var.yres * 3); - if (!t) { - put_img(dst, image); - return; - } - - pic = image; - - /* Decode the image into a table where each color component - * takes exatly one byte */ - for (i = 0; i < fb_var.xres * fb_var.yres; i++) { - - if (bytespp == 2) { - h = *(u16*)pic; - } else if (bytespp == 3) { - h = *(u32*)pic & 0xffffff; - } else /* if (bytespp == 4) */ { - h = *(u32*)pic; - } - - pic += bytespp; - - r = ((h >> fb_var.red.offset & ((1 << rlen)-1)) << rl8); - g = ((h >> fb_var.green.offset & ((1 << glen)-1)) << gl8); - b = ((h >> fb_var.blue.offset & ((1 << blen)-1)) << bl8); - - t[i*3] = r; - t[i*3+1] = g; - t[i*3+2] = b; - } - - /* Compute the color look-up table */ - for (step = 0; step < FADEIN_STEPS; step++) { - for (i = 0; i < 256; i++) { - clut[i][step] = (step+1) * i / FADEIN_STEPS; - } - } - - memset(dst, 0, fb_var.yres * fb_fix.line_length); - - for (step = 0; step < FADEIN_STEPS; step++) { - - pic = dst; - p = t; - - for (y = 0; y < fb_var.yres; y++) { - - for (x = 0; x < fb_var.xres; x++) { - - r = *p; p++; - g = *p; p++; - b = *p; p++; - - rt = clut[r][step]; - gt = clut[g][step]; - bt = clut[b][step]; - - if (bytespp == 2) { - rt >>= rl8; - gt >>= gl8; - bt >>= bl8; - } - - h = (rt << fb_var.red.offset) | - (gt << fb_var.green.offset) | - (bt << fb_var.blue.offset); - - if (bytespp == 2) { - *(u16*)pic = h; - pic += 2; - } else if (bytespp == 3) { - - if (endianess == little) { - *(u16*)pic = h & 0xffff; - pic[2] = (h >> 16) & 0xff; - } else { - *(u16*)pic = (h >> 8) & 0xffff; - pic[2] = h & 0xff; - } - pic += 3; - } else if (bytespp == 4) { - *(u32*)pic = h; - pic += 4; - } - } - - pic += fb_fix.line_length - fb_var.xres * bytespp; - } - } - - free(t); -} - -void fade_in(u8 *dst, u8 *image, struct fb_cmap cmap, u8 bgnd, int fd) -{ - if (bgnd) { - if (fork()) - return; - } - - /* FIXME: We need to handle 8bpp modes */ - if (cmap.red) { - put_img(dst, image); - return; - } - - if (fb_fix.visual == FB_VISUAL_DIRECTCOLOR) { - fade_in_directcolor(dst, image, fd); - } else { - fade_in_truecolor(dst, image); - } - - if (bgnd) { - exit(0); - } - - return; -} - -void set_directcolor_cmap(int fd) -{ - int len, i; - struct fb_cmap cmap; - - len = min(min(fb_var.red.length,fb_var.green.length),fb_var.blue.length); - - cmap.start = 0; - cmap.len = (1 << len); - cmap.transp = NULL; - cmap.red = malloc(2 * 256 * 3); - if (!cmap.red) - return; - - cmap.green = cmap.red + 256; - cmap.blue = cmap.green + 256; - - for (i = 0; i < cmap.len; i++) { - cmap.red[i] = cmap.green[i] = cmap.blue[i] = (0xffff * i)/(cmap.len-1); - } - - ioctl(fd, FBIOPUTCMAP, &cmap); - free(cmap.red); -} - diff -Naurp suspend2-userui/fbsplash/image.c s2-userui-mod/fbsplash/image.c --- suspend2-userui/fbsplash/image.c 2007-07-26 17:55:58.000000000 +0200 +++ s2-userui-mod/fbsplash/image.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,415 +0,0 @@ -/* - * image.c - Functions to load & unpack PNGs and JPEGs - * - * TuxOnIce userui adaptations: - * Copyright (C) 2005 Bernard Blackham - * - * Based on the original splashutils code: - * Copyright (C) 2004-2005, Michal Januszewski - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ - -#include -#include -#include - -#include "config.h" - -#ifdef CONFIG_PNG -#ifdef TARGET_KERNEL - #include "libs/libpng-1.2.8/png.h" -#else - #include -#endif -#endif - -#ifdef TARGET_KERNEL - #include "libs/jpeg-6b/jpeglib.h" -#else - #include -#endif - -#include "splash.h" - -struct fb_image verbose_img; -struct fb_image silent_img; - -typedef struct { - u8 r, g, b; -} __attribute__ ((packed)) rgbcolor; - -/* This function converts a truecolor image to whatever format the - * framebuffer uses */ -void truecolor2fb (truecolor* data, u8* out, int len, int y, u8 alpha) -{ - int i, add = 0; - rgbcolor* rgb = (rgbcolor*)data; - - add ^= (0 ^ y) & 1 ? 1 : 3; - - for (i = 0; i < len; i++) { - if (alpha) { - put_pixel(data->a, data->r, data->g, data->b, out, out, add); - data++; - } else { - put_pixel(255, rgb->r, rgb->g, rgb->b, out, out, add); - rgb++; - } - - out += bytespp; - add ^= 3; - } -} - -#ifdef CONFIG_PNG -#define PALETTE_COLORS 240 -int load_png(char *filename, u8 **data, struct fb_cmap *cmap, int *width, int *height, u8 want_alpha) -{ - png_structp png_ptr; - png_infop info_ptr, end_info; - png_bytep row_pointer; - png_colorp palette; - int rowbytes, num_palette; - int i, j, bytespp = (fb_var.bits_per_pixel + 7) >> 3; - u8 *buf = NULL; - u8 *t; - FILE *fp; - - if (want_alpha) - bytespp = 4; - - fp = fopen(filename,"r"); - if (!fp) - { - printerr("Could not open file %s.\n", filename); - return -1; - } - - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); - printerr("Could not allocate PNG info struct. Out of memory?\n"); - return -1; - } - - end_info = png_create_info_struct(png_ptr); - if (!end_info) - { - png_destroy_read_struct(&png_ptr, (png_infopp)&info_ptr, (png_infopp)NULL); - printerr("Could not read file %s. Corrupt PNG header?\n", filename); - return -1; - } - - if (setjmp(png_jmpbuf(png_ptr))) - goto failed; - - png_init_io(png_ptr, fp); - png_read_info(png_ptr, info_ptr); - - if (cmap && info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) { - printerr("Could not read file %s. Not a palette-based image.\n", filename); - goto failed; - } - - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY || - info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - png_set_gray_to_rgb(png_ptr); - - if (info_ptr->bit_depth == 16) - png_set_strip_16(png_ptr); - - if (!want_alpha && info_ptr->color_type & PNG_COLOR_MASK_ALPHA) - png_set_strip_alpha(png_ptr); - -#ifndef TARGET_KERNEL - if (!(info_ptr->color_type & PNG_COLOR_MASK_ALPHA) & want_alpha) { - png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER); - } -#endif - png_read_update_info(png_ptr, info_ptr); - - if (!cmap && info_ptr->color_type != PNG_COLOR_TYPE_RGB && info_ptr->color_type != PNG_COLOR_TYPE_RGBA) { - printerr("Could not read file %s. Not an RGB image.\n", filename); - goto failed; - } - - if (cmap) { - png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette); - - if (num_palette > cmap->len) { - printerr("Could not read file %s. Too many colours in image (%d > %d).\n", filename, num_palette, cmap->len); - goto failed; - } - } - - rowbytes = png_get_rowbytes(png_ptr, info_ptr); - - if ((width && *width && info_ptr->width != *width) || (height && *height && info_ptr->height != *height)) { - printerr("Image size mismatch: %s.\n", filename); - goto failed; - } else { - *width = info_ptr->width; - *height = info_ptr->height; - } - - *data = malloc(fb_var.xres * fb_var.yres * bytespp); - if (!*data) { - printerr("Failed to allocate memory for image: %s.\n", filename); - goto failed; - } - - buf = malloc(rowbytes); - if (!buf) { - printerr("Failed to allocate memory for image line buffer.\n"); - free(*data); - goto failed; - } - - for (i = 0; i < info_ptr->height; i++) { - if (cmap) { - row_pointer = *data + info_ptr->width * i; - } else if (want_alpha) { - row_pointer = *data + info_ptr->width * i * 4; - } else { - row_pointer = buf; - } - - png_read_row(png_ptr, row_pointer, NULL); - - if (cmap) { - int h = 256 - cmap->len; - t = *data + info_ptr->width * i; - - if (h) { - /* Move the colors up by 'h' offset. This is used because fbcon - * takes the first 16 colors. */ - for (j = 0; j < rowbytes; j++) { - t[j] += h; - } - } - - /* We only need to convert the image if we the alpha channel is not required */ - } else if (!want_alpha) { - truecolor2fb((truecolor*)buf, *data + info_ptr->width * bytespp * i, info_ptr->width, i, 0); - } - } - - if (cmap) { - for (i = 0; i < cmap->len; i++) { - cmap->red[i] = palette[i].red * 257; - cmap->green[i] = palette[i].green * 257; - cmap->blue[i] = palette[i].blue * 257; - } - } - - free(buf); - fclose(fp); - - png_destroy_read_struct(&png_ptr, (png_infopp)&info_ptr, (png_infopp)&end_info); - return 0; -failed: - png_destroy_read_struct(&png_ptr, (png_infopp)&info_ptr, (png_infopp)&end_info); - return -1; -} - -int is_png(char *filename) -{ - char header[8]; - FILE *fp = fopen(filename,"r"); - - if (!fp) - return -1; - - fread(header, 1, 8, fp); - fclose(fp); - - return !png_sig_cmp(header, 0, 8); -} -#endif /* PNG */ - -int load_jpeg(char *filename, u8 **data, int *width, int *height) -{ - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - FILE* injpeg; - - u8 *buf = NULL; - int i, bytespp = (fb_var.bits_per_pixel+7) >> 3; - - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - - if ((injpeg = fopen(filename,"r")) == NULL) { - printerr("Can't open file %s!\n", filename); - return -1; - } - - jpeg_stdio_src(&cinfo, injpeg); - jpeg_read_header(&cinfo, TRUE); - jpeg_start_decompress(&cinfo); - - if ((width && cinfo.output_width != *width) || (height && cinfo.output_height != *height)) { - printerr("Image size mismatch: %s.\n", filename); - return -2; - } else { - *width = cinfo.output_width; - *height = cinfo.output_height; - } - - buf = malloc(cinfo.output_width * cinfo.output_components * sizeof(char)); - if (!buf) { - printerr("Failed to allocate JPEG decompression buffer.\n"); - return -1; - } - - *data = malloc(cinfo.output_width * cinfo.output_height * bytespp); - if (!*data) { - printerr("Failed to allocate memory for image: %s.\n", filename); - return -4; - } - - for (i = 0; i < cinfo.output_height; i++) { - jpeg_read_scanlines(&cinfo, (JSAMPARRAY) &buf, 1); - truecolor2fb((truecolor*)buf, *data + cinfo.output_width * bytespp * i, cinfo.output_width, i, 0); - } - - jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - fclose(injpeg); - - free(buf); - return 0; -} - -int load_bg_images(char mode) -{ - struct fb_image *img = (mode == 'v') ? &verbose_img : &silent_img; - char *pic; - int i; - - img->width = fb_var.xres; - img->height = fb_var.yres; - img->depth = fb_var.bits_per_pixel; - - /* Deal with 8bpp modes. Only PNGs can be loaded, and pic256 - * option has to be used to specify the filename of the image */ - if (fb_var.bits_per_pixel == 8) { - pic = (mode == 'v') ? cf_pic256 : cf_silentpic256; - - if (!pic) { - printerr("No 8bpp %s picture specified in the theme config.\n", (mode == 'v') ? "verbose" : "silent" ); - return -1; - } - -#ifdef CONFIG_PNG - if (!is_png(pic)) { - printerr("Unrecognized format of the verbose 8bpp background image.\n"); - return -1; - } - - /* We have a palette of 256 colors, but fbcon takes 16 of these for - * font colors in verbose mode, so we have 240 left for the picture */ - if (mode != 's') { - i = PALETTE_COLORS; - img->cmap.start = 16; - } else { - i = 256; - img->cmap.start = 0; - } - - img->cmap.transp = NULL; - img->cmap.red = malloc(i * 3 * 2); - - if (!img->cmap.red) { - printerr("Failed to allocate memory for the image palette.\n"); - return -4; - } - - img->cmap.green = img->cmap.red + i; - img->cmap.blue = img->cmap.green + i; - img->cmap.len = i; - - if (load_png(pic, (u8**)&img->data, &img->cmap, &img->width, &img->height, 0)) { - printerr("Failed to load PNG file %s.\n", pic); - return -1; - } -#else - printerr("This version of splashutils has been compiled without support for 8bpp modes.\n"); - return -1; -#endif - /* Deal with 15, 16, 24 and 32bpp modes */ - } else { - pic = (mode == 'v') ? cf_pic : cf_silentpic; - - if (!pic) { - if (mode == 's') /* only complain about the silent pic */ - printerr("No silent picture specified in the theme config.\n"); - return -1; - } - -#ifdef CONFIG_PNG - if (is_png(pic)) { - i = load_png(pic, (u8**)&img->data, NULL, &img->width, &img->height, 0); - } else -#endif - { - i = load_jpeg(pic, (u8**)&img->data, &img->width, &img->height); - } - - if (i) { - printerr("Failed to load image %s.\n", pic); - return -1; - } - } - - return 0; -} - - -int load_images(char mode) -{ - item *i; - - if (!config_file) { - printerr("No config file specified.\n"); - return -1; - } - - if (mode == 'v' || mode == 'a') - if (load_bg_images('v')) - return -2; - - if (mode == 's' || mode == 'a') { - if (load_bg_images('s')) - return -2; - -#ifdef CONFIG_PNG - for (i = icons.head; i != NULL; i = i->next) { - icon_img *ii = (icon_img*) i->p; - ii->w = ii->h = 0; - - if (!is_png(ii->filename)) { - printerr("Icon %s is not a PNG file.\n", ii->filename); - continue; - } - - if (load_png(ii->filename, &ii->picbuf, NULL, &ii->w, &ii->h, 1)) { - printerr("Failed to load icon %s.\n", ii->filename); - ii->picbuf = NULL; - ii->w = ii->h = 0; - continue; - } - } -#endif - } - - return 0; -} - - diff -Naurp suspend2-userui/fbsplash/linux/console_splash.h s2-userui-mod/fbsplash/linux/console_splash.h --- suspend2-userui/fbsplash/linux/console_splash.h 2006-08-11 01:49:27.000000000 +0200 +++ s2-userui-mod/fbsplash/linux/console_splash.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,13 +0,0 @@ -#ifndef _LINUX_CONSOLE_SPLASH_H_ -#define _LINUX_CONSOLE_SPLASH_H_ 1 - -/* A structure used by the framebuffer splash code (drivers/video/fbsplash.c) */ -struct vc_splash { - __u8 bg_color; /* The color that is to be treated as transparent */ - __u8 state; /* Current splash state: 0 = off, 1 = on */ - __u16 tx, ty; /* Top left corner coordinates of the text field */ - __u16 twidth, theight; /* Width and height of the text field */ - char* theme; -}; - -#endif diff -Naurp suspend2-userui/fbsplash/linux/fb.h s2-userui-mod/fbsplash/linux/fb.h --- suspend2-userui/fbsplash/linux/fb.h 2006-08-11 01:49:27.000000000 +0200 +++ s2-userui-mod/fbsplash/linux/fb.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,952 +0,0 @@ -#ifndef _LINUX_FB_H -#define _LINUX_FB_H - -#include - -/* Definitions of frame buffers */ - -#define FB_MAJOR 29 -#define FB_MAX 32 /* sufficient for now */ - -struct fb_splash_iowrapper -{ - unsigned short vc; /* Virtual console */ - unsigned char origin; /* Point of origin of the request */ - void *data; -}; - -/* ioctls - 0x46 is 'F' */ -#define FBIOGET_VSCREENINFO 0x4600 -#define FBIOPUT_VSCREENINFO 0x4601 -#define FBIOGET_FSCREENINFO 0x4602 -#define FBIOGETCMAP 0x4604 -#define FBIOPUTCMAP 0x4605 -#define FBIOPAN_DISPLAY 0x4606 -#ifdef __KERNEL__ -#define FBIO_CURSOR _IOWR('F', 0x08, struct fb_cursor_user) -#else -#define FBIO_CURSOR _IOWR('F', 0x08, struct fb_cursor) -#endif -/* 0x4607-0x460B are defined below */ -/* #define FBIOGET_MONITORSPEC 0x460C */ -/* #define FBIOPUT_MONITORSPEC 0x460D */ -/* #define FBIOSWITCH_MONIBIT 0x460E */ -#define FBIOGET_CON2FBMAP 0x460F -#define FBIOPUT_CON2FBMAP 0x4610 -#define FBIOBLANK 0x4611 /* arg: 0 or vesa level + 1 */ -#define FBIOGET_VBLANK _IOR('F', 0x12, struct fb_vblank) -#define FBIO_ALLOC 0x4613 -#define FBIO_FREE 0x4614 -#define FBIOGET_GLYPH 0x4615 -#define FBIOGET_HWCINFO 0x4616 -#define FBIOPUT_MODEINFO 0x4617 -#define FBIOGET_DISPINFO 0x4618 -#define FBIOSPLASH_SETCFG _IOWR('F', 0x19, struct fb_splash_iowrapper) -#define FBIOSPLASH_GETCFG _IOR('F', 0x1A, struct fb_splash_iowrapper) -#define FBIOSPLASH_SETSTATE _IOWR('F', 0x1B, struct fb_splash_iowrapper) -#define FBIOSPLASH_GETSTATE _IOR('F', 0x1C, struct fb_splash_iowrapper) -#define FBIOSPLASH_SETPIC _IOWR('F', 0x1D, struct fb_splash_iowrapper) - -#define FB_SPLASH_THEME_LEN 128 /* Maximum lenght of a theme name */ -#define FB_SPLASH_IO_ORIG_KERNEL 0 /* Kernel ioctl origin */ -#define FB_SPLASH_IO_ORIG_USER 1 /* User ioctl origin */ - -#define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */ -#define FB_TYPE_PLANES 1 /* Non interleaved planes */ -#define FB_TYPE_INTERLEAVED_PLANES 2 /* Interleaved planes */ -#define FB_TYPE_TEXT 3 /* Text/attributes */ -#define FB_TYPE_VGA_PLANES 4 /* EGA/VGA planes */ - -#define FB_AUX_TEXT_MDA 0 /* Monochrome text */ -#define FB_AUX_TEXT_CGA 1 /* CGA/EGA/VGA Color text */ -#define FB_AUX_TEXT_S3_MMIO 2 /* S3 MMIO fasttext */ -#define FB_AUX_TEXT_MGA_STEP16 3 /* MGA Millenium I: text, attr, 14 reserved bytes */ -#define FB_AUX_TEXT_MGA_STEP8 4 /* other MGAs: text, attr, 6 reserved bytes */ - -#define FB_AUX_VGA_PLANES_VGA4 0 /* 16 color planes (EGA/VGA) */ -#define FB_AUX_VGA_PLANES_CFB4 1 /* CFB4 in planes (VGA) */ -#define FB_AUX_VGA_PLANES_CFB8 2 /* CFB8 in planes (VGA) */ - -#define FB_VISUAL_MONO01 0 /* Monochr. 1=Black 0=White */ -#define FB_VISUAL_MONO10 1 /* Monochr. 1=White 0=Black */ -#define FB_VISUAL_TRUECOLOR 2 /* True color */ -#define FB_VISUAL_PSEUDOCOLOR 3 /* Pseudo color (like atari) */ -#define FB_VISUAL_DIRECTCOLOR 4 /* Direct color */ -#define FB_VISUAL_STATIC_PSEUDOCOLOR 5 /* Pseudo color readonly */ - -#define FB_ACCEL_NONE 0 /* no hardware accelerator */ -#define FB_ACCEL_ATARIBLITT 1 /* Atari Blitter */ -#define FB_ACCEL_AMIGABLITT 2 /* Amiga Blitter */ -#define FB_ACCEL_S3_TRIO64 3 /* Cybervision64 (S3 Trio64) */ -#define FB_ACCEL_NCR_77C32BLT 4 /* RetinaZ3 (NCR 77C32BLT) */ -#define FB_ACCEL_S3_VIRGE 5 /* Cybervision64/3D (S3 ViRGE) */ -#define FB_ACCEL_ATI_MACH64GX 6 /* ATI Mach 64GX family */ -#define FB_ACCEL_DEC_TGA 7 /* DEC 21030 TGA */ -#define FB_ACCEL_ATI_MACH64CT 8 /* ATI Mach 64CT family */ -#define FB_ACCEL_ATI_MACH64VT 9 /* ATI Mach 64CT family VT class */ -#define FB_ACCEL_ATI_MACH64GT 10 /* ATI Mach 64CT family GT class */ -#define FB_ACCEL_SUN_CREATOR 11 /* Sun Creator/Creator3D */ -#define FB_ACCEL_SUN_CGSIX 12 /* Sun cg6 */ -#define FB_ACCEL_SUN_LEO 13 /* Sun leo/zx */ -#define FB_ACCEL_IMS_TWINTURBO 14 /* IMS Twin Turbo */ -#define FB_ACCEL_3DLABS_PERMEDIA2 15 /* 3Dlabs Permedia 2 */ -#define FB_ACCEL_MATROX_MGA2064W 16 /* Matrox MGA2064W (Millenium) */ -#define FB_ACCEL_MATROX_MGA1064SG 17 /* Matrox MGA1064SG (Mystique) */ -#define FB_ACCEL_MATROX_MGA2164W 18 /* Matrox MGA2164W (Millenium II) */ -#define FB_ACCEL_MATROX_MGA2164W_AGP 19 /* Matrox MGA2164W (Millenium II) */ -#define FB_ACCEL_MATROX_MGAG100 20 /* Matrox G100 (Productiva G100) */ -#define FB_ACCEL_MATROX_MGAG200 21 /* Matrox G200 (Myst, Mill, ...) */ -#define FB_ACCEL_SUN_CG14 22 /* Sun cgfourteen */ -#define FB_ACCEL_SUN_BWTWO 23 /* Sun bwtwo */ -#define FB_ACCEL_SUN_CGTHREE 24 /* Sun cgthree */ -#define FB_ACCEL_SUN_TCX 25 /* Sun tcx */ -#define FB_ACCEL_MATROX_MGAG400 26 /* Matrox G400 */ -#define FB_ACCEL_NV3 27 /* nVidia RIVA 128 */ -#define FB_ACCEL_NV4 28 /* nVidia RIVA TNT */ -#define FB_ACCEL_NV5 29 /* nVidia RIVA TNT2 */ -#define FB_ACCEL_CT_6555x 30 /* C&T 6555x */ -#define FB_ACCEL_3DFX_BANSHEE 31 /* 3Dfx Banshee */ -#define FB_ACCEL_ATI_RAGE128 32 /* ATI Rage128 family */ -#define FB_ACCEL_IGS_CYBER2000 33 /* CyberPro 2000 */ -#define FB_ACCEL_IGS_CYBER2010 34 /* CyberPro 2010 */ -#define FB_ACCEL_IGS_CYBER5000 35 /* CyberPro 5000 */ -#define FB_ACCEL_SIS_GLAMOUR 36 /* SiS 300/630/540 */ -#define FB_ACCEL_3DLABS_PERMEDIA3 37 /* 3Dlabs Permedia 3 */ -#define FB_ACCEL_ATI_RADEON 38 /* ATI Radeon family */ -#define FB_ACCEL_I810 39 /* Intel 810/815 */ -#define FB_ACCEL_SIS_GLAMOUR_2 40 /* SiS 315, 650, 740 */ -#define FB_ACCEL_SIS_XABRE 41 /* SiS 330 ("Xabre") */ -#define FB_ACCEL_I830 42 /* Intel 830M/845G/85x/865G */ -#define FB_ACCEL_NV_10 43 /* nVidia Arch 10 */ -#define FB_ACCEL_NV_20 44 /* nVidia Arch 20 */ -#define FB_ACCEL_NV_30 45 /* nVidia Arch 30 */ -#define FB_ACCEL_NV_40 46 /* nVidia Arch 40 */ -#define FB_ACCEL_NEOMAGIC_NM2070 90 /* NeoMagic NM2070 */ -#define FB_ACCEL_NEOMAGIC_NM2090 91 /* NeoMagic NM2090 */ -#define FB_ACCEL_NEOMAGIC_NM2093 92 /* NeoMagic NM2093 */ -#define FB_ACCEL_NEOMAGIC_NM2097 93 /* NeoMagic NM2097 */ -#define FB_ACCEL_NEOMAGIC_NM2160 94 /* NeoMagic NM2160 */ -#define FB_ACCEL_NEOMAGIC_NM2200 95 /* NeoMagic NM2200 */ -#define FB_ACCEL_NEOMAGIC_NM2230 96 /* NeoMagic NM2230 */ -#define FB_ACCEL_NEOMAGIC_NM2360 97 /* NeoMagic NM2360 */ -#define FB_ACCEL_NEOMAGIC_NM2380 98 /* NeoMagic NM2380 */ - -#define FB_ACCEL_SAVAGE4 0x80 /* S3 Savage4 */ -#define FB_ACCEL_SAVAGE3D 0x81 /* S3 Savage3D */ -#define FB_ACCEL_SAVAGE3D_MV 0x82 /* S3 Savage3D-MV */ -#define FB_ACCEL_SAVAGE2000 0x83 /* S3 Savage2000 */ -#define FB_ACCEL_SAVAGE_MX_MV 0x84 /* S3 Savage/MX-MV */ -#define FB_ACCEL_SAVAGE_MX 0x85 /* S3 Savage/MX */ -#define FB_ACCEL_SAVAGE_IX_MV 0x86 /* S3 Savage/IX-MV */ -#define FB_ACCEL_SAVAGE_IX 0x87 /* S3 Savage/IX */ -#define FB_ACCEL_PROSAVAGE_PM 0x88 /* S3 ProSavage PM133 */ -#define FB_ACCEL_PROSAVAGE_KM 0x89 /* S3 ProSavage KM133 */ -#define FB_ACCEL_S3TWISTER_P 0x8a /* S3 Twister */ -#define FB_ACCEL_S3TWISTER_K 0x8b /* S3 TwisterK */ -#define FB_ACCEL_SUPERSAVAGE 0x8c /* S3 Supersavage */ -#define FB_ACCEL_PROSAVAGE_DDR 0x8d /* S3 ProSavage DDR */ -#define FB_ACCEL_PROSAVAGE_DDRK 0x8e /* S3 ProSavage DDR-K */ - -struct fb_fix_screeninfo { - char id[16]; /* identification string eg "TT Builtin" */ - unsigned long smem_start; /* Start of frame buffer mem */ - /* (physical address) */ - __u32 smem_len; /* Length of frame buffer mem */ - __u32 type; /* see FB_TYPE_* */ - __u32 type_aux; /* Interleave for interleaved Planes */ - __u32 visual; /* see FB_VISUAL_* */ - __u16 xpanstep; /* zero if no hardware panning */ - __u16 ypanstep; /* zero if no hardware panning */ - __u16 ywrapstep; /* zero if no hardware ywrap */ - __u32 line_length; /* length of a line in bytes */ - unsigned long mmio_start; /* Start of Memory Mapped I/O */ - /* (physical address) */ - __u32 mmio_len; /* Length of Memory Mapped I/O */ - __u32 accel; /* Indicate to driver which */ - /* specific chip/card we have */ - __u16 reserved[3]; /* Reserved for future compatibility */ -}; - -/* Interpretation of offset for color fields: All offsets are from the right, - * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you - * can use the offset as right argument to <<). A pixel afterwards is a bit - * stream and is written to video memory as that unmodified. This implies - * big-endian byte order if bits_per_pixel is greater than 8. - */ -struct fb_bitfield { - __u32 offset; /* beginning of bitfield */ - __u32 length; /* length of bitfield */ - __u32 msb_right; /* != 0 : Most significant bit is */ - /* right */ -}; - -#define FB_NONSTD_HAM 1 /* Hold-And-Modify (HAM) */ - -#define FB_ACTIVATE_NOW 0 /* set values immediately (or vbl)*/ -#define FB_ACTIVATE_NXTOPEN 1 /* activate on next open */ -#define FB_ACTIVATE_TEST 2 /* don't set, round up impossible */ -#define FB_ACTIVATE_MASK 15 - /* values */ -#define FB_ACTIVATE_VBL 16 /* activate values on next vbl */ -#define FB_CHANGE_CMAP_VBL 32 /* change colormap on vbl */ -#define FB_ACTIVATE_ALL 64 /* change all VCs on this fb */ -#define FB_ACTIVATE_FORCE 128 /* force apply even when no change*/ -#define FB_ACTIVATE_INV_MODE 256 /* invalidate videomode */ - -#define FB_ACCELF_TEXT 1 /* (OBSOLETE) see fb_info.flags and vc_mode */ - -#define FB_SYNC_HOR_HIGH_ACT 1 /* horizontal sync high active */ -#define FB_SYNC_VERT_HIGH_ACT 2 /* vertical sync high active */ -#define FB_SYNC_EXT 4 /* external sync */ -#define FB_SYNC_COMP_HIGH_ACT 8 /* composite sync high active */ -#define FB_SYNC_BROADCAST 16 /* broadcast video timings */ - /* vtotal = 144d/288n/576i => PAL */ - /* vtotal = 121d/242n/484i => NTSC */ -#define FB_SYNC_ON_GREEN 32 /* sync on green */ - -#define FB_VMODE_NONINTERLACED 0 /* non interlaced */ -#define FB_VMODE_INTERLACED 1 /* interlaced */ -#define FB_VMODE_DOUBLE 2 /* double scan */ -#define FB_VMODE_MASK 255 - -#define FB_VMODE_YWRAP 256 /* ywrap instead of panning */ -#define FB_VMODE_SMOOTH_XPAN 512 /* smooth xpan possible (internally used) */ -#define FB_VMODE_CONUPDATE 512 /* don't update x/yoffset */ - -#define PICOS2KHZ(a) (1000000000UL/(a)) -#define KHZ2PICOS(a) (1000000000UL/(a)) - -struct fb_var_screeninfo { - __u32 xres; /* visible resolution */ - __u32 yres; - __u32 xres_virtual; /* virtual resolution */ - __u32 yres_virtual; - __u32 xoffset; /* offset from virtual to visible */ - __u32 yoffset; /* resolution */ - - __u32 bits_per_pixel; /* guess what */ - __u32 grayscale; /* != 0 Graylevels instead of colors */ - - struct fb_bitfield red; /* bitfield in fb mem if true color, */ - struct fb_bitfield green; /* else only length is significant */ - struct fb_bitfield blue; - struct fb_bitfield transp; /* transparency */ - - __u32 nonstd; /* != 0 Non standard pixel format */ - - __u32 activate; /* see FB_ACTIVATE_* */ - - __u32 height; /* height of picture in mm */ - __u32 width; /* width of picture in mm */ - - __u32 accel_flags; /* (OBSOLETE) see fb_info.flags */ - - /* Timing: All values in pixclocks, except pixclock (of course) */ - __u32 pixclock; /* pixel clock in ps (pico seconds) */ - __u32 left_margin; /* time from sync to picture */ - __u32 right_margin; /* time from picture to sync */ - __u32 upper_margin; /* time from sync to picture */ - __u32 lower_margin; - __u32 hsync_len; /* length of horizontal sync */ - __u32 vsync_len; /* length of vertical sync */ - __u32 sync; /* see FB_SYNC_* */ - __u32 vmode; /* see FB_VMODE_* */ - __u32 rotate; /* angle we rotate counter clockwise */ - __u32 reserved[5]; /* Reserved for future compatibility */ -}; - -struct fb_cmap { - __u32 start; /* First entry */ - __u32 len; /* Number of entries */ - __u16 *red; /* Red values */ - __u16 *green; - __u16 *blue; - __u16 *transp; /* transparency, can be NULL */ -}; - -struct fb_con2fbmap { - __u32 console; - __u32 framebuffer; -}; - -/* VESA Blanking Levels */ -#define VESA_NO_BLANKING 0 -#define VESA_VSYNC_SUSPEND 1 -#define VESA_HSYNC_SUSPEND 2 -#define VESA_POWERDOWN 3 - - -enum { - /* screen: unblanked, hsync: on, vsync: on */ - FB_BLANK_UNBLANK = VESA_NO_BLANKING, - - /* screen: blanked, hsync: on, vsync: on */ - FB_BLANK_NORMAL = VESA_NO_BLANKING + 1, - - /* screen: blanked, hsync: on, vsync: off */ - FB_BLANK_VSYNC_SUSPEND = VESA_VSYNC_SUSPEND + 1, - - /* screen: blanked, hsync: off, vsync: on */ - FB_BLANK_HSYNC_SUSPEND = VESA_HSYNC_SUSPEND + 1, - - /* screen: blanked, hsync: off, vsync: off */ - FB_BLANK_POWERDOWN = VESA_POWERDOWN + 1 -}; - -#define FB_VBLANK_VBLANKING 0x001 /* currently in a vertical blank */ -#define FB_VBLANK_HBLANKING 0x002 /* currently in a horizontal blank */ -#define FB_VBLANK_HAVE_VBLANK 0x004 /* vertical blanks can be detected */ -#define FB_VBLANK_HAVE_HBLANK 0x008 /* horizontal blanks can be detected */ -#define FB_VBLANK_HAVE_COUNT 0x010 /* global retrace counter is available */ -#define FB_VBLANK_HAVE_VCOUNT 0x020 /* the vcount field is valid */ -#define FB_VBLANK_HAVE_HCOUNT 0x040 /* the hcount field is valid */ -#define FB_VBLANK_VSYNCING 0x080 /* currently in a vsync */ -#define FB_VBLANK_HAVE_VSYNC 0x100 /* verical syncs can be detected */ - -struct fb_vblank { - __u32 flags; /* FB_VBLANK flags */ - __u32 count; /* counter of retraces since boot */ - __u32 vcount; /* current scanline position */ - __u32 hcount; /* current scandot position */ - __u32 reserved[4]; /* reserved for future compatibility */ -}; - -/* Internal HW accel */ -#define ROP_COPY 0 -#define ROP_XOR 1 - -struct fb_copyarea { - __u32 dx; - __u32 dy; - __u32 width; - __u32 height; - __u32 sx; - __u32 sy; -}; - -struct fb_fillrect { - __u32 dx; /* screen-relative */ - __u32 dy; - __u32 width; - __u32 height; - __u32 color; - __u32 rop; -}; - -struct fb_image { - __u32 dx; /* Where to place image */ - __u32 dy; - __u32 width; /* Size of image */ - __u32 height; - __u32 fg_color; /* Only used when a mono bitmap */ - __u32 bg_color; - __u8 depth; /* Depth of the image */ - const char *data; /* Pointer to image data */ - struct fb_cmap cmap; /* color map info */ -}; - -/* - * hardware cursor control - */ - -#define FB_CUR_SETIMAGE 0x01 -#define FB_CUR_SETPOS 0x02 -#define FB_CUR_SETHOT 0x04 -#define FB_CUR_SETCMAP 0x08 -#define FB_CUR_SETSHAPE 0x10 -#define FB_CUR_SETSIZE 0x20 -#define FB_CUR_SETALL 0xFF - -struct fbcurpos { - __u16 x, y; -}; - -struct fb_cursor { - __u16 set; /* what to set */ - __u16 enable; /* cursor on/off */ - __u16 rop; /* bitop operation */ - const char *mask; /* cursor mask bits */ - struct fbcurpos hot; /* cursor hot spot */ - struct fb_image image; /* Cursor image */ -}; - -#ifdef __KERNEL__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct vm_area_struct; -struct fb_info; -struct device; -struct file; - -/* Definitions below are used in the parsed monitor specs */ -#define FB_DPMS_ACTIVE_OFF 1 -#define FB_DPMS_SUSPEND 2 -#define FB_DPMS_STANDBY 4 - -#define FB_DISP_DDI 1 -#define FB_DISP_ANA_700_300 2 -#define FB_DISP_ANA_714_286 4 -#define FB_DISP_ANA_1000_400 8 -#define FB_DISP_ANA_700_000 16 - -#define FB_DISP_MONO 32 -#define FB_DISP_RGB 64 -#define FB_DISP_MULTI 128 -#define FB_DISP_UNKNOWN 256 - -#define FB_SIGNAL_NONE 0 -#define FB_SIGNAL_BLANK_BLANK 1 -#define FB_SIGNAL_SEPARATE 2 -#define FB_SIGNAL_COMPOSITE 4 -#define FB_SIGNAL_SYNC_ON_GREEN 8 -#define FB_SIGNAL_SERRATION_ON 16 - -#define FB_MISC_PRIM_COLOR 1 -#define FB_MISC_1ST_DETAIL 2 /* First Detailed Timing is preferred */ -struct fb_chroma { - __u32 redx; /* in fraction of 1024 */ - __u32 greenx; - __u32 bluex; - __u32 whitex; - __u32 redy; - __u32 greeny; - __u32 bluey; - __u32 whitey; -}; - -struct fb_monspecs { - struct fb_chroma chroma; - struct fb_videomode *modedb; /* mode database */ - __u8 manufacturer[4]; /* Manufacturer */ - __u8 monitor[14]; /* Monitor String */ - __u8 serial_no[14]; /* Serial Number */ - __u8 ascii[14]; /* ? */ - __u32 modedb_len; /* mode database length */ - __u32 model; /* Monitor Model */ - __u32 serial; /* Serial Number - Integer */ - __u32 year; /* Year manufactured */ - __u32 week; /* Week Manufactured */ - __u32 hfmin; /* hfreq lower limit (Hz) */ - __u32 hfmax; /* hfreq upper limit (Hz) */ - __u32 dclkmin; /* pixelclock lower limit (Hz) */ - __u32 dclkmax; /* pixelclock upper limit (Hz) */ - __u16 input; /* display type - see FB_DISP_* */ - __u16 dpms; /* DPMS support - see FB_DPMS_ */ - __u16 signal; /* Signal Type - see FB_SIGNAL_* */ - __u16 vfmin; /* vfreq lower limit (Hz) */ - __u16 vfmax; /* vfreq upper limit (Hz) */ - __u16 gamma; /* Gamma - in fractions of 100 */ - __u16 gtf : 1; /* supports GTF */ - __u16 misc; /* Misc flags - see FB_MISC_* */ - __u8 version; /* EDID version... */ - __u8 revision; /* ...and revision */ - __u8 max_x; /* Maximum horizontal size (cm) */ - __u8 max_y; /* Maximum vertical size (cm) */ -}; - -struct fb_cmap_user { - __u32 start; /* First entry */ - __u32 len; /* Number of entries */ - __u16 __user *red; /* Red values */ - __u16 __user *green; - __u16 __user *blue; - __u16 __user *transp; /* transparency, can be NULL */ -}; - -struct fb_image_user { - __u32 dx; /* Where to place image */ - __u32 dy; - __u32 width; /* Size of image */ - __u32 height; - __u32 fg_color; /* Only used when a mono bitmap */ - __u32 bg_color; - __u8 depth; /* Depth of the image */ - const char __user *data; /* Pointer to image data */ - struct fb_cmap_user cmap; /* color map info */ -}; - -struct fb_cursor_user { - __u16 set; /* what to set */ - __u16 enable; /* cursor on/off */ - __u16 rop; /* bitop operation */ - const char __user *mask; /* cursor mask bits */ - struct fbcurpos hot; /* cursor hot spot */ - struct fb_image_user image; /* Cursor image */ -}; - -/* - * Register/unregister for framebuffer events - */ - -/* The resolution of the passed in fb_info about to change */ -#define FB_EVENT_MODE_CHANGE 0x01 -/* The display on this fb_info is beeing suspended, no access to the - * framebuffer is allowed any more after that call returns - */ -#define FB_EVENT_SUSPEND 0x02 -/* The display on this fb_info was resumed, you can restore the display - * if you own it - */ -#define FB_EVENT_RESUME 0x03 -/* An entry from the modelist was removed */ -#define FB_EVENT_MODE_DELETE 0x04 -/* A driver registered itself */ -#define FB_EVENT_FB_REGISTERED 0x05 -/* get console to framebuffer mapping */ -#define FB_EVENT_GET_CONSOLE_MAP 0x06 -/* set console to framebuffer mapping */ -#define FB_EVENT_SET_CONSOLE_MAP 0x07 -/* A display blank is requested */ -#define FB_EVENT_BLANK 0x08 -/* Private modelist is to be replaced */ -#define FB_EVENT_NEW_MODELIST 0x09 - -struct fb_event { - struct fb_info *info; - void *data; -}; - - -extern int fb_register_client(struct notifier_block *nb); -extern int fb_unregister_client(struct notifier_block *nb); - -/* - * Pixmap structure definition - * - * The purpose of this structure is to translate data - * from the hardware independent format of fbdev to what - * format the hardware needs. - */ - -#define FB_PIXMAP_DEFAULT 1 /* used internally by fbcon */ -#define FB_PIXMAP_SYSTEM 2 /* memory is in system RAM */ -#define FB_PIXMAP_IO 4 /* memory is iomapped */ -#define FB_PIXMAP_SYNC 256 /* set if GPU can DMA */ - -struct fb_pixmap { - u8 *addr; /* pointer to memory */ - u32 size; /* size of buffer in bytes */ - u32 offset; /* current offset to buffer */ - u32 buf_align; /* byte alignment of each bitmap */ - u32 scan_align; /* alignment per scanline */ - u32 access_align; /* alignment per read/write */ - u32 flags; /* see FB_PIXMAP_* */ - /* access methods */ - void (*outbuf)(struct fb_info *info, u8 *addr, u8 *src, unsigned int size); - u8 (*inbuf) (struct fb_info *info, u8 *addr); -}; - - -/* - * Frame buffer operations - * - * LOCKING NOTE: those functions must _ALL_ be called with the console - * semaphore held, this is the only suitable locking mecanism we have - * in 2.6. Some may be called at interrupt time at this point though. - */ - -struct fb_ops { - /* open/release and usage marking */ - struct module *owner; - int (*fb_open)(struct fb_info *info, int user); - int (*fb_release)(struct fb_info *info, int user); - - /* For framebuffers with strange non linear layouts or that do not - * work with normal memory mapped access - */ - ssize_t (*fb_read)(struct file *file, char __user *buf, size_t count, loff_t *ppos); - ssize_t (*fb_write)(struct file *file, const char __user *buf, size_t count, loff_t *ppos); - - /* checks var and eventually tweaks it to something supported, - * DO NOT MODIFY PAR */ - int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info); - - /* set the video mode according to info->var */ - int (*fb_set_par)(struct fb_info *info); - - /* set color register */ - int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green, - unsigned blue, unsigned transp, struct fb_info *info); - - /* blank display */ - int (*fb_blank)(int blank, struct fb_info *info); - - /* pan display */ - int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info); - - /* Draws a rectangle */ - void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect); - /* Copy data from area to another */ - void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region); - /* Draws a image to the display */ - void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image); - - /* Draws cursor */ - int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor); - - /* Rotates the display */ - void (*fb_rotate)(struct fb_info *info, int angle); - - /* wait for blit idle, optional */ - int (*fb_sync)(struct fb_info *info); - - /* perform fb specific ioctl (optional) */ - int (*fb_ioctl)(struct inode *inode, struct file *file, unsigned int cmd, - unsigned long arg, struct fb_info *info); - - /* Handle 32bit compat ioctl (optional) */ - long (*fb_compat_ioctl)(struct file *f, unsigned cmd, unsigned long arg, - struct fb_info *info); - - /* perform fb specific mmap */ - int (*fb_mmap)(struct fb_info *info, struct file *file, struct vm_area_struct *vma); -}; - -#ifdef CONFIG_FB_TILEBLITTING - -#define FB_TILE_CURSOR_NONE 0 -#define FB_TILE_CURSOR_UNDERLINE 1 -#define FB_TILE_CURSOR_LOWER_THIRD 2 -#define FB_TILE_CURSOR_LOWER_HALF 3 -#define FB_TILE_CURSOR_TWO_THIRDS 4 -#define FB_TILE_CURSOR_BLOCK 5 - -struct fb_tilemap { - __u32 width; /* width of each tile in pixels */ - __u32 height; /* height of each tile in scanlines */ - __u32 depth; /* color depth of each tile */ - __u32 length; /* number of tiles in the map */ - __u8 *data; /* actual tile map: a bitmap array, packed - to the nearest byte */ -}; - -struct fb_tilerect { - __u32 sx; /* origin in the x-axis */ - __u32 sy; /* origin in the y-axis */ - __u32 width; /* number of tiles in the x-axis */ - __u32 height; /* number of tiles in the y-axis */ - __u32 index; /* what tile to use: index to tile map */ - __u32 fg; /* foreground color */ - __u32 bg; /* background color */ - __u32 rop; /* raster operation */ -}; - -struct fb_tilearea { - __u32 sx; /* source origin in the x-axis */ - __u32 sy; /* source origin in the y-axis */ - __u32 dx; /* destination origin in the x-axis */ - __u32 dy; /* destination origin in the y-axis */ - __u32 width; /* number of tiles in the x-axis */ - __u32 height; /* number of tiles in the y-axis */ -}; - -struct fb_tileblit { - __u32 sx; /* origin in the x-axis */ - __u32 sy; /* origin in the y-axis */ - __u32 width; /* number of tiles in the x-axis */ - __u32 height; /* number of tiles in the y-axis */ - __u32 fg; /* foreground color */ - __u32 bg; /* background color */ - __u32 length; /* number of tiles to draw */ - __u32 *indices; /* array of indices to tile map */ -}; - -struct fb_tilecursor { - __u32 sx; /* cursor position in the x-axis */ - __u32 sy; /* cursor position in the y-axis */ - __u32 mode; /* 0 = erase, 1 = draw */ - __u32 shape; /* see FB_TILE_CURSOR_* */ - __u32 fg; /* foreground color */ - __u32 bg; /* background color */ -}; - -struct fb_tile_ops { - /* set tile characteristics */ - void (*fb_settile)(struct fb_info *info, struct fb_tilemap *map); - - /* all dimensions from hereon are in terms of tiles */ - - /* move a rectangular region of tiles from one area to another*/ - void (*fb_tilecopy)(struct fb_info *info, struct fb_tilearea *area); - /* fill a rectangular region with a tile */ - void (*fb_tilefill)(struct fb_info *info, struct fb_tilerect *rect); - /* copy an array of tiles */ - void (*fb_tileblit)(struct fb_info *info, struct fb_tileblit *blit); - /* cursor */ - void (*fb_tilecursor)(struct fb_info *info, - struct fb_tilecursor *cursor); -}; -#endif /* CONFIG_FB_TILEBLITTING */ - -/* FBINFO_* = fb_info.flags bit flags */ -#define FBINFO_MODULE 0x0001 /* Low-level driver is a module */ -#define FBINFO_HWACCEL_DISABLED 0x0002 - /* When FBINFO_HWACCEL_DISABLED is set: - * Hardware acceleration is turned off. Software implementations - * of required functions (copyarea(), fillrect(), and imageblit()) - * takes over; acceleration engine should be in a quiescent state */ - -/* hints */ -#define FBINFO_PARTIAL_PAN_OK 0x0040 /* otw use pan only for double-buffering */ -#define FBINFO_READS_FAST 0x0080 /* soft-copy faster than rendering */ - -/* hardware supported ops */ -/* semantics: when a bit is set, it indicates that the operation is - * accelerated by hardware. - * required functions will still work even if the bit is not set. - * optional functions may not even exist if the flag bit is not set. - */ -#define FBINFO_HWACCEL_NONE 0x0000 -#define FBINFO_HWACCEL_COPYAREA 0x0100 /* required */ -#define FBINFO_HWACCEL_FILLRECT 0x0200 /* required */ -#define FBINFO_HWACCEL_IMAGEBLIT 0x0400 /* required */ -#define FBINFO_HWACCEL_ROTATE 0x0800 /* optional */ -#define FBINFO_HWACCEL_XPAN 0x1000 /* optional */ -#define FBINFO_HWACCEL_YPAN 0x2000 /* optional */ -#define FBINFO_HWACCEL_YWRAP 0x4000 /* optional */ - -#define FBINFO_MISC_USEREVENT 0x10000 /* event request - from userspace */ -#define FBINFO_MISC_MODESWITCH 0x20000 /* mode switch */ -#define FBINFO_MISC_MODESWITCHLATE 0x40000 /* init hardware later */ -#define FBINFO_MISC_TILEBLITTING 0x80000 /* use tile blitting */ - -struct fb_info { - int node; - int flags; - struct fb_var_screeninfo var; /* Current var */ - struct fb_fix_screeninfo fix; /* Current fix */ - struct fb_monspecs monspecs; /* Current Monitor specs */ - struct work_struct queue; /* Framebuffer event queue */ - struct fb_pixmap pixmap; /* Image hardware mapper */ - struct fb_pixmap sprite; /* Cursor hardware mapper */ - struct fb_cmap cmap; /* Current cmap */ - struct list_head modelist; /* mode list */ - struct fb_videomode *mode; /* current mode */ - struct fb_ops *fbops; - struct device *device; - struct class_device *class_device; /* sysfs per device attrs */ -#ifdef CONFIG_FB_TILEBLITTING - struct fb_tile_ops *tileops; /* Tile Blitting */ -#endif - char __iomem *screen_base; /* Virtual address */ - unsigned long screen_size; /* Amount of ioremapped VRAM or 0 */ - void *pseudo_palette; /* Fake palette of 16 colors */ -#define FBINFO_STATE_RUNNING 0 -#define FBINFO_STATE_SUSPENDED 1 - u32 state; /* Hardware state i.e suspend */ - void *fbcon_par; /* fbcon use-only private area */ - - struct fb_image splash; - - /* From here on everything is device dependent */ - void *par; -}; - -#ifdef MODULE -#define FBINFO_DEFAULT FBINFO_MODULE -#else -#define FBINFO_DEFAULT 0 -#endif - -// This will go away -#define FBINFO_FLAG_MODULE FBINFO_MODULE -#define FBINFO_FLAG_DEFAULT FBINFO_DEFAULT - -/* This will go away - * fbset currently hacks in FB_ACCELF_TEXT into var.accel_flags - * when it wants to turn the acceleration engine on. This is - * really a separate operation, and should be modified via sysfs. - * But for now, we leave it broken with the following define - */ -#define STUPID_ACCELF_TEXT_SHIT - -// This will go away -#if defined(__sparc__) - -/* We map all of our framebuffers such that big-endian accesses - * are what we want, so the following is sufficient. - */ - -// This will go away -#define fb_readb sbus_readb -#define fb_readw sbus_readw -#define fb_readl sbus_readl -#define fb_readq sbus_readq -#define fb_writeb sbus_writeb -#define fb_writew sbus_writew -#define fb_writel sbus_writel -#define fb_writeq sbus_writeq -#define fb_memset sbus_memset_io - -#elif defined(__i386__) || defined(__alpha__) || defined(__x86_64__) || defined(__hppa__) || (defined(__sh__) && !defined(__SH5__)) || defined(__powerpc__) - -#define fb_readb __raw_readb -#define fb_readw __raw_readw -#define fb_readl __raw_readl -#define fb_readq __raw_readq -#define fb_writeb __raw_writeb -#define fb_writew __raw_writew -#define fb_writel __raw_writel -#define fb_writeq __raw_writeq -#define fb_memset memset_io - -#else - -#define fb_readb(addr) (*(volatile u8 *) (addr)) -#define fb_readw(addr) (*(volatile u16 *) (addr)) -#define fb_readl(addr) (*(volatile u32 *) (addr)) -#define fb_readq(addr) (*(volatile u64 *) (addr)) -#define fb_writeb(b,addr) (*(volatile u8 *) (addr) = (b)) -#define fb_writew(b,addr) (*(volatile u16 *) (addr) = (b)) -#define fb_writel(b,addr) (*(volatile u32 *) (addr) = (b)) -#define fb_writeq(b,addr) (*(volatile u64 *) (addr) = (b)) -#define fb_memset memset - -#endif - - /* - * `Generic' versions of the frame buffer device operations - */ - -extern int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var); -extern int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var); -extern int fb_blank(struct fb_info *info, int blank); -extern int soft_cursor(struct fb_info *info, struct fb_cursor *cursor); -extern void cfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect); -extern void cfb_copyarea(struct fb_info *info, const struct fb_copyarea *area); -extern void cfb_imageblit(struct fb_info *info, const struct fb_image *image); - -/* drivers/video/fbmem.c */ -extern int register_framebuffer(struct fb_info *fb_info); -extern int unregister_framebuffer(struct fb_info *fb_info); -extern int fb_prepare_logo(struct fb_info *fb_info); -extern int fb_show_logo(struct fb_info *fb_info); -extern char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size); -extern void fb_iomove_buf_unaligned(struct fb_info *info, struct fb_pixmap *buf, - u8 *dst, u32 d_pitch, u8 *src, u32 idx, - u32 height, u32 shift_high, u32 shift_low, u32 mod); -extern void fb_iomove_buf_aligned(struct fb_info *info, struct fb_pixmap *buf, - u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, - u32 height); -extern void fb_sysmove_buf_unaligned(struct fb_info *info, struct fb_pixmap *buf, - u8 *dst, u32 d_pitch, u8 *src, u32 idx, - u32 height, u32 shift_high, u32 shift_low, u32 mod); -extern void fb_sysmove_buf_aligned(struct fb_info *info, struct fb_pixmap *buf, - u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, - u32 height); -extern void fb_set_suspend(struct fb_info *info, int state); -extern int fb_get_color_depth(struct fb_var_screeninfo *var); -extern int fb_get_options(char *name, char **option); -extern int fb_new_modelist(struct fb_info *info); - -extern struct fb_info *registered_fb[FB_MAX]; -extern int num_registered_fb; - -/* drivers/video/fbsysfs.c */ -extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev); -extern void framebuffer_release(struct fb_info *info); -extern int fb_init_class_device(struct fb_info *fb_info); -extern void fb_cleanup_class_device(struct fb_info *head); - -/* drivers/video/fbmon.c */ -#define FB_MAXTIMINGS 0 -#define FB_VSYNCTIMINGS 1 -#define FB_HSYNCTIMINGS 2 -#define FB_DCLKTIMINGS 3 -#define FB_IGNOREMON 0x100 - -#define FB_MODE_IS_UNKNOWN 0 -#define FB_MODE_IS_DETAILED 1 -#define FB_MODE_IS_STANDARD 2 -#define FB_MODE_IS_VESA 4 -#define FB_MODE_IS_CALCULATED 8 -#define FB_MODE_IS_FIRST 16 -#define FB_MODE_IS_FROM_VAR 32 - -extern int fbmon_valid_timings(u_int pixclock, u_int htotal, u_int vtotal, - const struct fb_info *fb_info); -extern int fbmon_dpms(const struct fb_info *fb_info); -extern int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, - struct fb_info *info); -extern int fb_validate_mode(const struct fb_var_screeninfo *var, - struct fb_info *info); -extern int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var); -extern void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs); -extern void fb_destroy_modedb(struct fb_videomode *modedb); - -/* drivers/video/modedb.c */ -#define VESA_MODEDB_SIZE 34 -extern void fb_var_to_videomode(struct fb_videomode *mode, - struct fb_var_screeninfo *var); -extern void fb_videomode_to_var(struct fb_var_screeninfo *var, - struct fb_videomode *mode); -extern int fb_mode_is_equal(struct fb_videomode *mode1, - struct fb_videomode *mode2); -extern int fb_add_videomode(struct fb_videomode *mode, struct list_head *head); -extern void fb_delete_videomode(struct fb_videomode *mode, - struct list_head *head); -extern struct fb_videomode *fb_match_mode(struct fb_var_screeninfo *var, - struct list_head *head); -extern struct fb_videomode *fb_find_best_mode(struct fb_var_screeninfo *var, - struct list_head *head); -extern struct fb_videomode *fb_find_nearest_mode(struct fb_var_screeninfo *var, - struct list_head *head); -extern void fb_destroy_modelist(struct list_head *head); -extern void fb_videomode_to_modelist(struct fb_videomode *modedb, int num, - struct list_head *head); - -/* drivers/video/fbcmap.c */ -extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp); -extern void fb_dealloc_cmap(struct fb_cmap *cmap); -extern int fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to); -extern int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to); -extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info); -extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info); -extern struct fb_cmap *fb_default_cmap(int len); -extern void fb_invert_cmaps(void); - -struct fb_videomode { - const char *name; /* optional */ - u32 refresh; /* optional */ - u32 xres; - u32 yres; - u32 pixclock; - u32 left_margin; - u32 right_margin; - u32 upper_margin; - u32 lower_margin; - u32 hsync_len; - u32 vsync_len; - u32 sync; - u32 vmode; - u32 flag; -}; - -extern const struct fb_videomode vesa_modes[]; - -struct fb_modelist { - struct list_head list; - struct fb_videomode mode; -}; - -extern int fb_find_mode(struct fb_var_screeninfo *var, - struct fb_info *info, const char *mode_option, - const struct fb_videomode *db, - unsigned int dbsize, - const struct fb_videomode *default_mode, - unsigned int default_bpp); - -#endif /* __KERNEL__ */ - -#endif /* _LINUX_FB_H */ diff -Naurp suspend2-userui/fbsplash/list.c s2-userui-mod/fbsplash/list.c --- suspend2-userui/fbsplash/list.c 2007-07-26 17:55:58.000000000 +0200 +++ s2-userui-mod/fbsplash/list.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,31 +0,0 @@ -/* - * list.c - list utility functions - * - * TuxOnIce userui adaptations: - * Copyright (C) 2005 Bernard Blackham - * - * Based on the original splashutils code: - * Copyright (C) 2005 Michal Januszewski - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ -#include -#include "splash.h" - -void list_add(list *l, void *obj) -{ - if (l->tail != NULL) { - l->tail->next = malloc(sizeof(item)); - l->tail->next->p = obj; - l->tail->next->next = NULL; - l->tail = l->tail->next; - } else { - l->head = l->tail = malloc(sizeof(item)); - l->tail->next = NULL; - l->tail->p = obj; - } -} - diff -Naurp suspend2-userui/fbsplash/Makefile s2-userui-mod/fbsplash/Makefile --- suspend2-userui/fbsplash/Makefile 2006-08-11 01:49:27.000000000 +0200 +++ s2-userui-mod/fbsplash/Makefile 2007-08-11 14:24:08.000000000 +0200 @@ -1,15 +1,14 @@ CFLAGS := -Wall -O3 -g -INCLUDES = -I/usr/include/freetype2/ -I. +INCLUDES = . TARGET = userui_fbsplash.o -OBJECTS = userui_fbsplash_core.o cmd.o common.o effects.o image.o list.o \ - parse.o mng_callbacks.o mng_render.o render.o ttf.o +OBJECTS = userui_fbsplash_core.o SOURCES = $(patsubst %.o,%.c,$(OBJECTS)) all: $(TARGET) userui_fbsplash.o: $(OBJECTS) - $(CC) $(LDFLAGS) -r -nostdlib -nostartfiles $(SPLASH_LDLIBS) $^ -o $@ + $(CC) $(LDFLAGS) -r -nostdlib -nostartfiles -lfbsplashrender $^ -o $@ %.o: %.c ../userui.h config.h splash.h $(CC) $(CFLAGS) $(INCLUDES) -c $*.c -o $@ diff -Naurp suspend2-userui/fbsplash/mng_callbacks.c s2-userui-mod/fbsplash/mng_callbacks.c --- suspend2-userui/fbsplash/mng_callbacks.c 2006-08-11 01:49:27.000000000 +0200 +++ s2-userui-mod/fbsplash/mng_callbacks.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,186 +0,0 @@ -/* - * mng_callbacks.c - Callback functions for libmng - * - * Copyright (C) 2005 Bernard Blackham - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ - -#include -#include -#include -#include "splash.h" - -mng_ptr fb_mng_memalloc(mng_size_t len) -{ - return calloc(1, len); -} - -void fb_mng_memfree(mng_ptr p, mng_size_t len) -{ - free(p); -} - -static mng_bool fb_mng_openstream(mng_handle handle) -{ - mng_anim *mng = mng_get_userdata(handle); - - if (mng->data == NULL || mng->len == 0) - return MNG_FALSE; - - mng->ptr = 0; - mng->open = 1; - - return MNG_TRUE; -} - -static mng_bool fb_mng_closestream(mng_handle handle) -{ - mng_anim *mng = mng_get_userdata(handle); - - mng->open = 0; - return MNG_TRUE; -} - -static mng_bool fb_mng_readdata(mng_handle handle, mng_ptr buf, - mng_uint32 len, mng_uint32p pread) -{ - mng_anim *mng = mng_get_userdata(handle); - char *src_buf; - - if (mng->data == NULL || !mng->open) - return MNG_FALSE; - - src_buf = ((char*)mng->data) + mng->ptr; - - if (mng->ptr + len > mng->len) - len = mng->len - mng->ptr; - - memcpy(buf, src_buf, len); - if (pread) - *pread = len; - - mng->ptr += len; - - return MNG_TRUE; -} - -static mng_ptr fb_mng_getcanvasline(mng_handle handle, mng_uint32 line_num) -{ - mng_anim *mng = mng_get_userdata(handle); - - if (mng->canvas == NULL || line_num >= mng->canvas_h) { - fprintf(stderr, "%s(mngh, %d): Requested invalid line or canvas was NULL.\n", - __FUNCTION__, line_num); - return MNG_NULL; - } - - return mng->canvas + (line_num * mng->canvas_w * mng->canvas_bytes_pp); -} - -static mng_bool fb_mng_refresh(mng_handle handle, mng_uint32 x, mng_uint32 y, - mng_uint32 width, mng_uint32 height) -{ - - /* FIXME */ - return MNG_TRUE; -} - -static mng_uint32 fb_mng_gettickcount(mng_handle handle) -{ - struct timeval tv; - mng_anim *mng = mng_get_userdata(handle); - - if (gettimeofday(&tv, NULL) < 0) { - perror("fb_mng_gettickcount: gettimeofday"); - abort(); - } - - if (mng->start_time.tv_sec == 0) { - mng->start_time.tv_sec = tv.tv_sec; - mng->start_time.tv_usec = tv.tv_usec; - } - - return ((tv.tv_sec - mng->start_time.tv_sec)*1000) + - ((tv.tv_usec - mng->start_time.tv_usec)/1000); -} - -static mng_bool fb_mng_settimer(mng_handle handle, mng_uint32 msecs) -{ - mng_anim *mng = mng_get_userdata(handle); - - mng->wait_msecs = msecs; - return MNG_TRUE; -} - -static mng_bool fb_mng_processheader(mng_handle handle, mng_uint32 width, - mng_uint32 height) -{ - mng_anim *mng = mng_get_userdata(handle); - - free(mng->canvas); - - mng->canvas_bytes_pp = 4; - - if ((mng->canvas = malloc(width*height*mng->canvas_bytes_pp)) == NULL) { - fprintf(stderr, "%s: Unable to allocate memory for MNG canvas\n", - __FUNCTION__); - return MNG_FALSE; - } - mng->canvas_w = width; - mng->canvas_h = height; - - mng_set_canvasstyle(handle, MNG_CANVAS_RGBA8); - - mng_set_bgcolor(handle, 0, 0, 0); /* FIXME - make configurable? */ - - return MNG_TRUE; -} - -static mng_bool fb_mng_errorproc(mng_handle handler, mng_int32 code, - mng_int8 severity, mng_chunkid chunkname, mng_uint32 chunkseq, - mng_int32 extra1, mng_int32 extra2, mng_pchar errtext) -{ - fprintf(stderr, "libmng error: Code: %d, Severity: %d - %s\n", - code, severity, errtext); - abort(); - return MNG_TRUE; -} - -#ifdef MNG_SUPPORT_TRACE -static mng_bool fb_mng_traceproc(mng_handle handle, mng_int32 funcnr, - mng_int32 seq, mng_pchar funcname) -{ - fprintf(stderr, "libmng trace: %s (seq %d\n)", funcname, seq); - return MNG_TRUE; - -} -#endif - -mng_retcode mng_init_callbacks(mng_handle handle) -{ - mng_retcode ret; - -#define set_cb(x) \ - if ((ret = mng_setcb_##x(handle, fb_mng_##x)) != MNG_NOERROR) \ - return ret; - - set_cb(errorproc); - set_cb(openstream); - set_cb(closestream); - set_cb(readdata); - set_cb(getcanvasline); - set_cb(refresh); - set_cb(gettickcount); - set_cb(settimer); - set_cb(processheader); -#ifdef MNG_SUPPORT_TRACE - set_cb(traceproc); -#endif - -#undef set_cb - return MNG_NOERROR; -} diff -Naurp suspend2-userui/fbsplash/mng_render.c s2-userui-mod/fbsplash/mng_render.c --- suspend2-userui/fbsplash/mng_render.c 2006-08-11 01:49:27.000000000 +0200 +++ s2-userui-mod/fbsplash/mng_render.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,228 +0,0 @@ -/* - * mng_render.c - Functions for rendering MNG animations. - * - * Copyright (C) 2005 Bernard Blackham - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ - -#include -#include -#include -#include -#include -#include "splash.h" - -static int mng_readfile(mng_handle mngh, char *filename) -{ - int fd, len; - char *file_data; - struct stat sb; - mng_anim *mng = mng_get_userdata(mngh); - - if ((fd = open(filename, O_RDONLY)) < 0) { - perror("mng_readfile: open"); - return 0; - } - if (fstat(fd, &sb) == -1) { - perror("mng_readfile: stat"); - goto close_fail; - } - mng->len = sb.st_size; - - if ((mng->data = malloc(mng->len)) == NULL) { - fprintf(stderr, "mng_readfile: Unable to allocate memory for MNG file\n"); - goto close_fail; - } - - len = 0; - file_data = mng->data; - while (len < mng->len) { - int ret; - int amt = 0x10000; - if (mng->len - len < amt) - amt = mng->len - len; - ret = read(fd, file_data, amt); /* read up to 64KB at a time */ - switch (ret) { - case -1: - perror("mng_readfile: read"); - goto close_fail; - case 0: - fprintf(stderr, "mng_readfile: Shorter file than expected!\n"); - goto close_fail; - } - file_data += ret; - len += ret; - } - - close(fd); - - return 1; - -close_fail: - close(fd); - return 0; -} - -mng_handle mng_load(char* filename) -{ - mng_handle mngh; - mng_anim *mng; - - mng = (mng_anim*)malloc(sizeof(mng_anim)); - if (!mng) { - fprintf(stderr, "%s: Unable to allocate memory for MNG data\n", - __FUNCTION__); - return MNG_NULL; - } - - memset(mng, 0, sizeof(mng_anim)); - - mngh = mng_initialize(mng, fb_mng_memalloc, fb_mng_memfree, - MNG_NULL); - if (mngh == MNG_NULL) { - fprintf(stderr, "%s: mng_initialize failed\n", __FUNCTION__); - goto freemem_fail; - } - - if (mng_init_callbacks(mngh)) { - print_mng_error(mngh, "mng_init_callbacks failed"); - goto cleanup_fail; - } - - /* Load the file into memory */ - if (!mng_readfile(mngh, filename)) - goto cleanup_fail; - - /* Read and parse the file */ - if (mng_read(mngh) != MNG_NOERROR) { - /* Do something about it. */ - print_mng_error(mngh, "mng_read failed"); - goto cleanup_fail; - } - - mng->num_frames = mng_get_totalframes(mngh); - - return mngh; - -cleanup_fail: - mng_cleanup(&mngh); -freemem_fail: - free(mng); - return MNG_NULL; -} - -void mng_done(mng_handle mngh) -{ - mng_cleanup(&mngh); -} - -mng_retcode mng_render_next(mng_handle mngh) -{ - mng_anim *mng = mng_get_userdata(mngh); - mng_retcode ret; - int last_frame = 0; - - /* last_frame = mng_get_currentframe(mngh) == mng->num_frames; FIXME */ - if (!mng->displayed_first) { - ret = mng_display(mngh); - if (ret == MNG_NOERROR || ret == MNG_NEEDTIMERWAIT) - mng->displayed_first = 1; - } else - ret = mng_display_resume(mngh); - - if (last_frame) - return MNG_NOERROR; - - if (ret == MNG_NEEDTIMERWAIT || ret == MNG_NOERROR) - return ret; - - print_mng_error(mngh, "mng_display failed"); - - return ret; -} - -mng_retcode mng_render_proportional(mng_handle mngh, int progress) -{ - mng_anim *mng = mng_get_userdata(mngh); - mng_retcode ret = MNG_NOERROR; - int frame_num, current_frame; - - frame_num = ((progress * mng->num_frames) / PROGRESS_MAX) + 1; - if (frame_num > mng->num_frames) - frame_num = mng->num_frames; - - if (!mng->displayed_first) { - ret = mng_display(mngh); - mng->displayed_first = 1; - } - - current_frame = mng_get_currentframe(mngh); - if (current_frame == frame_num) - return ret; - - /* Don't bother freezing if the next frame is just n+1. mng_display_resume - * will do this case by default, and it saves us from the horrid hack - * below. - */ - if (frame_num != current_frame + 1) { - mng_display_freeze(mngh); - - /* XXX: hack! workaround what seems to be a bug in libmng - it won't - * actually repaint the canvas if you wind an animation "forwards" - * using goframe, only backwards, so go to the end of the animation first. - */ - - mng_display_goframe(mngh, mng->num_frames); - if (frame_num != mng->num_frames) - mng_display_goframe(mngh, frame_num); - } - - ret = mng_display_resume(mngh); - - if (ret == MNG_NEEDTIMERWAIT || ret == MNG_NOERROR) - return ret; - - print_mng_error(mngh, "mng_display failed"); - - return ret; -} - -int mng_display_next(mng_handle mngh, unsigned char* dest, int x, int y) -{ - truecolor *src; - mng_anim *mng = mng_get_userdata(mngh); - int dispwidth, dispheight, line; - - dest += y * fb_var.xres * bytespp; - src = (truecolor*)mng->canvas; - - if (x + mng->canvas_w > fb_var.xres) - dispwidth = fb_var.xres - x; - else - dispwidth = mng->canvas_w; - - if (y + mng->canvas_h > fb_var.yres) - dispheight = fb_var.yres - y; - else - dispheight = mng->canvas_h; - - for (line = 0; line < dispheight; line++) { - truecolor2fb(src, dest + (x * bytespp), dispwidth, y + line, 1); - dest += fb_var.xres * bytespp; - src += mng->canvas_w; - } - - return 1; -} - -mng_retcode mng_display_restart(mng_handle mngh) -{ - mng_anim *mng = mng_get_userdata(mngh); - - mng->displayed_first = 0; - return mng_display_reset(mngh); -} diff -Naurp suspend2-userui/fbsplash/mng_splash.h s2-userui-mod/fbsplash/mng_splash.h --- suspend2-userui/fbsplash/mng_splash.h 2006-08-11 01:49:27.000000000 +0200 +++ s2-userui-mod/fbsplash/mng_splash.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,57 +0,0 @@ -#ifndef _FBANIM_MNG_H_ -#define _FBANIM_MNG_H_ - -#include -#include -#include -#include -#include "splash.h" - -typedef struct { - void *data; - int len, ptr, open; - - char *canvas; - int canvas_h, canvas_w, canvas_bytes_pp; - - int wait_msecs; - struct timeval start_time; - int displayed_first; - int num_frames; -} mng_anim; - -/* mng_render.c */ -extern mng_handle mng_load(char *filename); -extern void mng_done(mng_handle mngh); -extern mng_retcode mng_render_next(mng_handle mngh); -extern int mng_display_next(mng_handle mngh, unsigned char* dest, int x, int y); -extern mng_retcode mng_render_proportional(mng_handle mngh, int progress); - -/* mng_callbacks.c */ -extern mng_ptr fb_mng_memalloc(mng_size_t len); -extern void fb_mng_memfree(mng_ptr p, mng_size_t len); -extern mng_retcode mng_init_callbacks(mng_handle handle); -extern mng_retcode mng_display_restart(mng_handle mngh); - -/* MNG-error printing functions */ -static inline void __print_mng_error(mng_handle mngh, char* s, ...) -{ - va_list ap; - - mng_int8 severity; - mng_chunkid chunkname; - mng_uint32 chunkseq; - mng_int32 extra1, extra2; - mng_pchar err_text; - mng_getlasterror(mngh, &severity, &chunkname, &chunkseq, - &extra1, &extra2, &err_text); - va_start(ap, s); - vfprintf(stderr, s, ap); - va_end(ap); - fprintf(stderr, ": %s\n", err_text); -} -#define print_mng_error(mngh, s, x...) do { \ - __print_mng_error(mngh, "%s: "s, __FUNCTION__, ## x); \ - } while (0) - -#endif /* _FBANIM_MNG_H_ */ diff -Naurp suspend2-userui/fbsplash/parse.c s2-userui-mod/fbsplash/parse.c --- suspend2-userui/fbsplash/parse.c 2007-07-26 17:55:58.000000000 +0200 +++ s2-userui-mod/fbsplash/parse.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,1039 +0,0 @@ -/* - * parse.c - Functions for parsing splashutils config files - * - * TuxOnIce userui adaptations: - * Copyright (C) 2005 Bernard Blackham - * - * Based on the original splashutils code: - * Copyright (C) 2004-2005, Michal Januszewski - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ - -#include -#include -#include -#include -#include -#include -#include "splash.h" - -struct config_opt { - char *name; - enum { t_int, t_path, t_box, t_icon, t_rect, t_anim, t_color, t_fontpath, - t_text } type; - void *val; -}; - -list fonts = { NULL, NULL }; -list icons = { NULL, NULL }; -list objs = { NULL, NULL }; -list rects = { NULL, NULL }; - -char *cf_silentpic = NULL; -char *cf_pic = NULL; -char *cf_silentpic256 = NULL; /* pictures for 8bpp modes */ -char *cf_pic256 = NULL; - -struct splash_config cf; -int line = 0; - -/* Note that pic256 and silentpic256 have to be located before pic and - * silentpic or we are gonna get a parse error @ pic256/silentpic256. */ -struct config_opt opts[] = -{ - { .name = "jpeg", - .type = t_path, - .val = &cf_pic }, - - { .name = "pic256", - .type = t_path, - .val = &cf_pic256 }, - - { .name = "silentpic256", - .type = t_path, - .val = &cf_silentpic256 }, - - { .name = "silentjpeg", - .type = t_path, - .val = &cf_silentpic }, - - { .name = "pic", - .type = t_path, - .val = &cf_pic }, - - { .name = "silentpic", - .type = t_path, - .val = &cf_silentpic }, - - { .name = "bg_color", - .type = t_int, - .val = &cf.bg_color }, - - { .name = "tx", - .type = t_int, - .val = &cf.tx }, - - { .name = "ty", - .type = t_int, - .val = &cf.ty }, - - { .name = "tw", - .type = t_int, - .val = &cf.tw }, - - { .name = "th", - .type = t_int, - .val = &cf.th }, - - { .name = "box", - .type = t_box, - .val = NULL }, - - { .name = "icon", - .type = t_icon, - .val = NULL }, - - { .name = "rect", - .type = t_rect, - .val = NULL }, - - { .name = "anim", - .type = t_anim, - .val = NULL }, - -#if (defined(CONFIG_TTY_KERNEL) && defined(TARGET_KERNEL)) || defined(CONFIG_TTF) - { .name = "text_x", - .type = t_int, - .val = &cf.text_x }, - - { .name = "text_y", - .type = t_int, - .val = &cf.text_y }, - - { .name = "text_size", - .type = t_int, - .val = &cf.text_size }, - - { .name = "text_color", - .type = t_color, - .val = &cf.text_color }, - - { .name = "text_font", - .type = t_fontpath, - .val = &cf.text_font }, - - { .name = "text", - .type = t_text, - .val = NULL }, -#endif /* TTF */ -}; - -int ishexdigit(char c) -{ - return (isdigit(c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) ? 1 : 0; -} - -void skip_whitespace(char **buf) -{ - while (**buf == ' ' || **buf == '\t') - (*buf)++; - - return; -} - -void skip_nonwhitespace(char **buf) -{ - while (**buf != ' ' && **buf != '\t') - (*buf)++; - - return; -} - -void parse_int(char *t, struct config_opt opt) -{ - if (*t != '=') { - fprintf(stderr, "parse error @ line %d\n", line); - return; - } - - t++; skip_whitespace(&t); - *(u16*)opt.val = strtol(t,NULL,0); -} - -void parse_path(char *t, struct config_opt opt) -{ - if (*t != '=') { - fprintf(stderr, "parse error @ line %d\n", line); - return; - } - - t++; skip_whitespace(&t); - *(char**)opt.val = get_filepath(t); -} - -char *get_fontpath(char *t) -{ - char buf[512]; - char buf2[512]; - struct stat st1, st2; - - if (t[0] == '/') { - return strdup(t); - } - - snprintf(buf, 512, "%s/%s/%s", THEME_DIR, arg_theme, t); - snprintf(buf2, 512, "%s/%s", THEME_DIR, t); - - stat(buf, &st1); - stat(buf2, &st2); - - if (S_ISREG(st1.st_mode) || S_ISLNK(st1.st_mode)) { - return strdup(buf); - } else if (S_ISREG(st2.st_mode) || S_ISLNK(st2.st_mode)) { - return strdup(buf2); - } else { - return strdup(buf); - } - - return NULL; -} - -void parse_fontpath(char *t, struct config_opt opt) -{ - if (*t != '=') { - fprintf(stderr, "parse error @ line %d\n", line); - return; - } - - t++; skip_whitespace(&t); - *(char**)opt.val = get_fontpath(t); -} - -int parse_color(char **t, struct color *cl) -{ - u32 h, len = 0; - char *p; - - if (**t != '#') { - if (strncmp(*t, "0x", 2)) - return -1; - else - (*t) += 2; - } else { - (*t)++; - } - - for (p = *t; ishexdigit(*p); p++, len++); - - p = *t; - h = strtoul(*t, &p, 16); - if (*t == p) - return -2; - - if (len > 6) { - cl->a = h & 0xff; - cl->r = (h >> 24) & 0xff; - cl->g = (h >> 16) & 0xff; - cl->b = (h >> 8) & 0xff; - } else { - cl->a = 0xff; - cl->r = (h >> 16) & 0xff; - cl->g = (h >> 8 ) & 0xff; - cl->b = h & 0xff; - } - - *t = p; - - return 0; -} - -int is_in_svclist(char *svc, char *list) -{ - char *data = getenv(list); - int l = strlen(svc); - - if (!data) - return 0; - - skip_whitespace(&data); - - while (1) { - - if (data[0] == 0) - break; - - if (!strncmp(data, svc, l) && (data[l] == ' ' || data[l] == 0)) - return 1; - - for ( ; data[0] != 0 && data[0] != ' '; data++); - - skip_whitespace(&data); - } - - return 0; -} - -int parse_svc_state(char *t, enum ESVC *state) -{ - if (!strncmp(t, "svc_inactive_start", 18)) { - *state = e_svc_inact_start; return 18; - } else if (!strncmp(t, "svc_inactive_stop", 17)) { - *state = e_svc_inact_stop; return 17; - } else if (!strncmp(t, "svc_started", 11)) { - *state = e_svc_started; return 11; - } else if (!strncmp(t, "svc_stopped", 11)) { - *state = e_svc_stopped; return 11; - } else if (!strncmp(t, "svc_start_failed", 17)) { - *state = e_svc_start_failed; return 17; - } else if (!strncmp(t, "svc_stop_failed", 16)) { - *state = e_svc_stop_failed; return 16; - } else if (!strncmp(t, "svc_stop", 8)) { - *state = e_svc_stop; return 8; - } else if (!strncmp(t, "svc_start", 9)) { - *state = e_svc_start; return 9; - } - - return 0; -} - -void parse_icon(char *t) -{ - char *filename = NULL; - char *p; - icon *cic = malloc(sizeof(icon)); - icon_img *cim; - item *ti; - obj *cobj; - int i; - - if (!cic) - return; - - cic->svc = NULL; - - skip_whitespace(&t); - for (i = 0; t[i] != ' ' && t[i] != '\t' && t[i] != '\0'; i++); - t[i] = 0; - - filename = get_filepath(t); - t += (i+1); - - skip_whitespace(&t); - cic->x = strtol(t,&p,0); - if (t == p) - goto pi_err; - - t = p; skip_whitespace(&t); - cic->y = strtol(t,&p,0); - if (t == p) - goto pi_err; - - t = p; skip_whitespace(&t); - - i = parse_svc_state(t, &cic->type); - - if (i) - t += i; - else - cic->type = e_display; - - skip_whitespace(&t); - for (i = 0; t[i] != ' ' && t[i] != '\t' && t[i] != '\0'; i++); - t[i] = 0; - i = 0; - - if (arg_task != start_daemon) { - - switch (cic->type) { - - case e_svc_inact_start: - if (is_in_svclist(t, "SPL_SVC_INACTIVE_START")) - i = 1; - break; - - case e_svc_inact_stop: - if (is_in_svclist(t, "SPL_SVC_INACTIVE_STOP")) - i = 1; - break; - - case e_svc_started: - if (is_in_svclist(t, "SPL_SVC_STARTED")) - i = 1; - break; - - case e_svc_stopped: - if (is_in_svclist(t, "SPL_SVC_STOPPED")) - i = 1; - break; - - case e_svc_start_failed: - if (is_in_svclist(t, "SPL_SVC_START_FAILED")) - i = 1; - break; - - case e_svc_stop_failed: - if (is_in_svclist(t, "SPL_SVC_STOP_FAILED")) - i = 1; - break; - - case e_svc_stop: - if (is_in_svclist(t, "SPL_SVC_STOP")) - i = 1; - break; - - case e_svc_start: - if (is_in_svclist(t, "SPL_SVC_START")) - i = 1; - break; - - case e_display: - i = 1; - break; - } - - if (!i) - goto pi_out; - - cic->status = 1; - } else { - - if (cic->type == e_display) - cic->status = 1; - else - cic->status = 0; - } - - if (cic->type != e_display) { - cic->svc = strdup(t); - } - - for (ti = icons.head ; ti != NULL; ti = ti->next) { - icon_img *ii = (icon_img*) ti->p; - - if (!strcmp(ii->filename, filename)) { - cic->img = ii; - goto pi_end; - } - } - - /* Allocate a new entry in the icons list */ - cim = malloc(sizeof(icon_img)); - if (!cim) - goto pi_outm; - cim->filename = filename; - cim->w = cim->h = 0; - cim->picbuf = NULL; - list_add(&icons, cim); - cic->img = cim; - -pi_end: - cobj = malloc(sizeof(obj)); - if (!cobj) { -pi_outm: fprintf(stderr, "Cannot allocate memory (parse_icon)!"); - goto pi_out; - } - cobj->type = o_icon; - cobj->p = cic; - - list_add(&objs, cobj); - return; - -pi_err: fprintf(stderr, "parse error @ line %d\n", line); -pi_out: if (filename) - free(filename); - if (cic->svc) - free(cic->svc); - free(cic); - return; -} - -void parse_rect(char *t) -{ - char *p; - rect *crect = malloc(sizeof(rect)); - - if (!crect) - return; - - skip_whitespace(&t); - - while (!isdigit(*t)) { - t++; - } - - crect->x1 = strtol(t,&p,0); - if (t == p) - goto pr_err; - t = p; skip_whitespace(&t); - crect->y1 = strtol(t,&p,0); - if (t == p) - goto pr_err; - t = p; skip_whitespace(&t); - crect->x2 = strtol(t,&p,0); - if (t == p) - goto pr_err; - t = p; skip_whitespace(&t); - crect->y2 = strtol(t,&p,0); - if (t == p) - goto pr_err; - t = p; skip_whitespace(&t); - - /* sanity checks */ - if (crect->x1 >= fb_var.xres) - crect->x1 = fb_var.xres-1; - if (crect->x2 >= fb_var.xres) - crect->x2 = fb_var.xres-1; - if (crect->y1 >= fb_var.yres) - crect->y1 = fb_var.yres-1; - if (crect->y2 >= fb_var.yres) - crect->y2 = fb_var.yres-1; - - list_add(&rects, crect); - return; -pr_err: - fprintf(stderr, "parse error @ line %d\n", line); - free(crect); - return; -} - -#if defined(CONFIG_MNG) && !defined(TARGET_KERNEL) -void parse_anim(char *t) -{ - char *p; - char *filename; - obj *cobj = NULL; - anim *canim = malloc(sizeof(anim)); - - if (!canim) - return; - - skip_whitespace(&t); - canim->flags = 0; - - while (1) { - if (!strncmp(t, "verbose", 7)) { - canim->flags |= F_ANIM_VERBOSE; - t += 7; - } else if (!strncmp(t, "silent", 6)) { - canim->flags |= F_ANIM_SILENT; - t += 6; - } else { - skip_whitespace(&t); - break; - } - - skip_whitespace(&t); - } - - if (canim->flags == 0) - canim->flags = F_ANIM_SILENT | F_ANIM_VERBOSE; - - if (!strncmp(t, "once", 4)) { - canim->flags |= F_ANIM_ONCE; - t += 4; - } else if (!strncmp(t, "loop", 4)) { - canim->flags |= F_ANIM_LOOP; - t += 4; - } else if (!strncmp(t, "proportional", 12)) { - canim->flags |= F_ANIM_PROPORTIONAL; - t += 12; - } else { - goto pa_err; - } - - skip_whitespace(&t); - - filename = t; - skip_nonwhitespace(&t); - *t = '\0'; - t++; - - skip_whitespace(&t); - - canim->x = strtol(t,&p,0); - if (t == p) - goto pa_err; - t = p; skip_whitespace(&t); - - canim->y = strtol(t,&p,0); - if (t == p) - goto pa_err; - t = p; skip_whitespace(&t); - - /* sanity checks */ - if (canim->x >= fb_var.xres) - canim->x = fb_var.xres-1; - if (canim->y >= fb_var.yres) - canim->y = fb_var.yres-1; - - canim->status = 0; - - filename = get_filepath(filename); - - canim->mng = mng_load(filename); - if (!canim->mng) { - free(filename); - printerr("Cannot allocate memory for mng (parse_anim)!\n"); - goto pa_out; - } - - free(filename); - - cobj = malloc(sizeof(obj)); - if (!cobj) { - printerr("Cannot allocate memory (parse_anim)!\n"); - goto pa_out; - } - cobj->type = o_anim; - cobj->p = canim; - list_add(&objs, cobj); - return; -pa_err: - fprintf(stderr, "parse error @ line %d\n", line); -pa_out: - free(canim); - return; -} -#endif /* CONFIG_MNG */ - -void parse_box(char *t) -{ - char *p; - int ret; - box *cbox = malloc(sizeof(box)); - obj *cobj = NULL; - - if (!cbox) - return; - - skip_whitespace(&t); - cbox->attr = 0; - - while (!isdigit(*t)) { - if (!strncmp(t,"noover",6)) { - cbox->attr |= BOX_NOOVER; - t += 6; - } else if (!strncmp(t, "inter", 5)) { - cbox->attr |= BOX_INTER; - t += 5; - } else if (!strncmp(t, "silent", 6)) { - cbox->attr |= BOX_SILENT; - t += 6; - } else { - goto pb_err; - } - - skip_whitespace(&t); - } - - cbox->x1 = strtol(t,&p,0); - if (t == p) - goto pb_err; - t = p; skip_whitespace(&t); - cbox->y1 = strtol(t,&p,0); - if (t == p) - goto pb_err; - t = p; skip_whitespace(&t); - cbox->x2 = strtol(t,&p,0); - if (t == p) - goto pb_err; - t = p; skip_whitespace(&t); - cbox->y2 = strtol(t,&p,0); - if (t == p) - goto pb_err; - t = p; skip_whitespace(&t); - - /* sanity checks */ - if (cbox->x1 >= fb_var.xres) - cbox->x1 = fb_var.xres-1; - if (cbox->x2 >= fb_var.xres) - cbox->x2 = fb_var.xres-1; - if (cbox->y1 >= fb_var.yres) - cbox->y1 = fb_var.yres-1; - if (cbox->y2 >= fb_var.yres) - cbox->y2 = fb_var.yres-1; - -#define zero_color(cl) *(u32*)(&cl) = 0; -#define is_zero_color(cl) (*(u32*)(&cl) == 0) -#define assign_color(c1, c2) *(u32*)(&c1) = *(u32*)(&c2); - - zero_color(cbox->c_ul); - zero_color(cbox->c_ur); - zero_color(cbox->c_ll); - zero_color(cbox->c_lr); - - if (parse_color(&t, &cbox->c_ul)) - goto pb_err; - - skip_whitespace(&t); - - ret = parse_color(&t, &cbox->c_ur); - - if (ret == -1) { - assign_color(cbox->c_ur, cbox->c_ul); - assign_color(cbox->c_lr, cbox->c_ul); - assign_color(cbox->c_ll, cbox->c_ul); - goto pb_end; - } else if (ret == -2) - goto pb_err; - - skip_whitespace(&t); - - if (parse_color(&t, &cbox->c_ll)) - goto pb_err; - - skip_whitespace(&t); - - if (parse_color(&t, &cbox->c_lr)) - goto pb_err; -pb_end: - cobj = malloc(sizeof(obj)); - if (!cobj) { - free(cbox); - fprintf(stderr, "Cannot allocate memory (parse_box)!"); - return; - } - cobj->type = o_box; - cobj->p = cbox; - - list_add(&objs, cobj); - return; - -pb_err: - fprintf(stderr, "parse error @ line %d\n", line); - free(cbox); - return; -} - -char *parse_quoted_string(char *t, u8 keepvar) -{ - char *p, *out; - int cnt = 0; - int len = 0; - int i; - - if (*t != '"') - return NULL; - - t++; - p = t; - - while ((*p != '"' || *(p-1) == '\\') && *p != 0) { - if (*p == '\\' && *(p+1) == '"') - cnt++; - p++; - } - - if (*p != '"') - return NULL; - - len = p-t; - out = malloc(len - cnt + 1); - if (!out) { - printerr("Failed to allocate memory for a quoted string.\n"); - return NULL; - } - - for (i = 0; i < len; i++, t++) { - if (*t == '\\' && i < len-1) { - if (!keepvar || (keepvar && *(t+1) == '"')) - t++; - } - out[i] = *t; - } - - out[len-cnt] = 0; - return out; -} - -#if (defined(CONFIG_TTY_KERNEL) && defined(TARGET_KERNEL)) || defined(CONFIG_TTF) -void parse_text(char *t) -{ - char *p, *fontname = NULL, *fpath = NULL; - int ret, fontsize; - text *ct = malloc(sizeof(text)); - obj *cobj = NULL; - item *ti; - font_e *fe; - - if (!ct) - return; - - skip_whitespace(&t); - ct->flags = 0; - ct->hotspot = 0; - ct->style = TTF_STYLE_NORMAL; - ret = 1; - - while (!isdigit(*t) && ret) { - - if (!strncmp(t, "silent", 6)) { - ct->flags |= F_TXT_SILENT; - t += 6; - ret = 1; - } else if (!strncmp(t, "verbose", 7)) { - ct->flags |= F_TXT_VERBOSE; - t += 7; - ret = 1; - } else { - ret = 0; - } - - skip_whitespace(&t); - } - - if (ct->flags == 0) - ct->flags = F_TXT_VERBOSE | F_TXT_SILENT; - - if (!isdigit(*t)) { - p = t; - skip_nonwhitespace(&p); - fontname = t; - *p = 0; - t = p+1; - } - skip_whitespace(&t); - - /* Parse the style selector */ - while(!isdigit(*t)) { - if (*t == 'b') { - ct->style |= TTF_STYLE_BOLD; - } else if (*t == 'i') { - ct->style |= TTF_STYLE_ITALIC; - } else if (*t == 'u') { - ct->style |= TTF_STYLE_UNDERLINE; - } else if (*t != ' ' && *t != '\t') { - goto pt_err; - } - t++; - } - - /* Parse font size */ - fontsize = strtol(t,&p,0); - if (t == p) - goto pt_err; - - t = p; skip_whitespace(&t); - - /* Parse x position */ - ct->x = strtol(t,&p,0); - if (t == p) - goto pt_err; - t = p; skip_whitespace(&t); - - if (!isdigit(*t)) { - if (!strncmp(t, "left", 4)) { - ct->hotspot |= F_HS_LEFT; - t += 4; - } else if (!strncmp(t, "right", 5)) { - ct->hotspot |= F_HS_RIGHT; - t += 5; - } else if (!strncmp(t, "middle", 6)) { - ct->hotspot |= F_HS_HMIDDLE; - t += 6; - } else { - goto pt_err; - } - - skip_whitespace(&t); - } else { - ct->hotspot |= F_HS_LEFT; - } - - /* Parse y position */ - ct->y = strtol(t,&p,0); - if (t == p) - goto pt_err; - t = p; skip_whitespace(&t); - - if (!strncmp(t, "top", 3)) { - ct->hotspot |= F_HS_TOP; - t += 3; - } else if (!strncmp(t, "bottom", 6)) { - ct->hotspot |= F_HS_BOTTOM; - t += 6; - } else if (!strncmp(t, "middle", 6)) { - ct->hotspot |= F_HS_VMIDDLE; - t += 6; - } else { - ct->hotspot |= F_HS_TOP; - } - - skip_whitespace(&t); - - /* Sanity checks */ - if (ct->x >= fb_var.xres) - goto pt_err; - - if (ct->x < 0) - ct->x = 0; - - if (ct->y >= fb_var.yres) - goto pt_err; - - if (ct->y < 0) - ct->y = 0; - - zero_color(ct->col); - - if (parse_color(&t, &ct->col)) - goto pt_err; - - skip_whitespace(&t); - if (!strncmp(t, "exec", 4)) { - ct->flags |= F_TXT_EXEC; - t += 4; - } else if (!strncmp(t, "eval", 4)) { - ct->flags |= F_TXT_EVAL; - t += 4; - } - - skip_whitespace(&t); - ct->val = parse_quoted_string(t, (ct->flags & F_TXT_EVAL) ? 1 : 0); - if (!ct->val) - goto pt_err; - - if (!fontname) - fontname = DEFAULT_FONT; - - fpath = get_fontpath(fontname); - - for (ti = fonts.head ; ti != NULL; ti = ti->next) { - fe = (font_e*) ti->p; - - if (!strcmp(fe->file, fpath) && fe->size == fontsize) { - ct->font = fe; - goto pt_end; - } - } - - /* Allocate a new entry in the fonts list */ - fe = malloc(sizeof(font_e)); - if (!fe) - goto pt_outm; - fe->file = fpath; - fe->size = fontsize; - fe->font = NULL; - - list_add(&fonts, fe); - ct->font = fe; - -pt_end: cobj = malloc(sizeof(obj)); - if (!cobj) { -pt_outm: printerr("Cannot allocate memory (parse_text)!\n"); - goto pt_out; - } - cobj->type = o_text; - cobj->p = ct; - list_add(&objs, cobj); - return; - -pt_err: - printerr("parse error @ line %d\n", line); -pt_out: free(ct); - if (fpath) - free(fpath); - return; -} -#endif /* TTF */ - -int parse_cfg(char *cfgfile) -{ - FILE* cfg; - char buf[1024]; - char *t; - int len, i; - - if ((cfg = fopen(cfgfile,"r")) == NULL) { - fprintf(stderr, "Can't open config file %s.\n", cfgfile); - return 1; - } - - while (fgets(buf, sizeof(buf), cfg)) { - - line++; - - len = strlen(buf); - - if (len == 0 || len == sizeof(buf)-1) - continue; - - buf[len-1] = 0; /* get rid of \n */ - - t = buf; - skip_whitespace(&t); - - /* skip comments */ - if (*t == '#') - continue; - - for (i = 0; i < sizeof(opts) / sizeof(struct config_opt); i++) - { - if (!strncmp(opts[i].name, t, strlen(opts[i].name))) { - - t += strlen(opts[i].name); - skip_whitespace(&t); - - switch(opts[i].type) { - - case t_path: - parse_path(t, opts[i]); - break; - - case t_fontpath: - parse_fontpath(t, opts[i]); - break; - - case t_color: - { - if (*t != '=') { - fprintf(stderr, "parse error @ line %d\n", line); - break; - } - - t++; - skip_whitespace(&t); - parse_color(&t, opts[i].val); - break; - } - - case t_int: - parse_int(t, opts[i]); - break; - - case t_box: - parse_box(t); - break; - - case t_icon: - parse_icon(t); - break; - - case t_rect: - parse_rect(t); - break; - -#if defined(CONFIG_MNG) && !defined(TARGET_KERNEL) - case t_anim: - parse_anim(t); - break; -#endif -#if (defined(CONFIG_TTY_KERNEL) && defined(TARGET_KERNEL)) || defined(CONFIG_TTF) - case t_text: - parse_text(t); - break; -#endif - } - } - } - } - - fclose(cfg); - return 0; -} - - diff -Naurp suspend2-userui/fbsplash/render.c s2-userui-mod/fbsplash/render.c --- suspend2-userui/fbsplash/render.c 2007-07-26 17:55:58.000000000 +0200 +++ s2-userui-mod/fbsplash/render.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,583 +0,0 @@ -/* - * render.c - Functions for rendering boxes and icons - * - * TuxOnIce userui adaptations: - * Copyright (C) 2005 Bernard Blackham - * - * Based on the original splashutils code: - * Copyright (C) 2004-2005, Michal Januszewski - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ - -/* HACK WARNING: - * This is necessary to get FD_SET and FD_ZERO on platforms other than x86. */ -#ifdef TARGET_KERNEL -#define __KERNEL__ -#include -#undef __KERNEL__ -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include "splash.h" - -void render_icon(icon *ticon, u8 *target) -{ - int y, yi; - int bytespp = (fb_var.bits_per_pixel + 7) >> 3; - u8 *out = NULL; - u8 *in = NULL; - - for (y = ticon->y, yi = 0; yi < ticon->img->h; yi++, y++) { - out = target + (ticon->x + y * fb_var.xres) * bytespp; - in = ticon->img->picbuf + yi * ticon->img->w * 4; - truecolor2fb((truecolor*)in, out, ticon->img->w, y, 1); - } -} - -inline void put_pixel (u8 a, u8 r, u8 g, u8 b, u8 *src, u8 *dst, u8 add) -{ - if (fb_opt) { - if (a != 255) { - dst[fb_ro] = (src[fb_ro]*(255-a) + r*a) / 255; - dst[fb_go] = (src[fb_go]*(255-a) + g*a) / 255; - dst[fb_bo] = (src[fb_bo]*(255-a) + b*a) / 255; - } else { - dst[fb_ro] = r; - dst[fb_go] = g; - dst[fb_bo] = b; - } - } else { - u32 i; - u8 tr, tg, tb; - - if (a != 255) { - if (fb_var.bits_per_pixel == 16) { - i = *(u16*)src; - } else if (fb_var.bits_per_pixel == 24) { - i = *(u32*)src & 0xffffff; - } else if (fb_var.bits_per_pixel == 32) { - i = *(u32*)src; - } else { - i = *(u32*)src & ((2 << fb_var.bits_per_pixel)-1); - } - - tr = (( (i >> fb_var.red.offset & ((1 << fb_rlen)-1)) - << (8 - fb_rlen)) * (255 - a) + r * a) / 255; - tg = (( (i >> fb_var.green.offset & ((1 << fb_glen)-1)) - << (8 - fb_glen)) * (255 - a) + g * a) / 255; - tb = (( (i >> fb_var.blue.offset & ((1 << fb_blen)-1)) - << (8 - fb_blen)) * (255 - a) + b * a) / 255; - } else { - tr = r; - tg = g; - tb = b; - } - - /* We only need to do dithering if depth is <24bpp */ - if (fb_var.bits_per_pixel < 24) { - tr = CLAMP(tr + add*2 + 1); - tg = CLAMP(tg + add); - tb = CLAMP(tb + add*2 + 1); - } - - tr >>= (8 - fb_rlen); - tg >>= (8 - fb_glen); - tb >>= (8 - fb_blen); - - i = (tr << fb_var.red.offset) | - (tg << fb_var.green.offset) | - (tb << fb_var.blue.offset); - - if (fb_var.bits_per_pixel == 16) { - *(u16*)dst = i; - } else if (fb_var.bits_per_pixel == 24) { - if (endianess == little) { - *(u16*)dst = i & 0xffff; - dst[2] = (i >> 16) & 0xff; - } else { - *(u16*)dst = (i >> 8) & 0xffff; - dst[2] = i & 0xff; - } - } else if (fb_var.bits_per_pixel == 32) { - *(u32*)dst = i; - } - } -} - -void render_box2(box *box, u8 *target) -{ - int x, y, a, r, g, b; - int add = 0; - u8 *pic; - u8 solid = 0; - - int b_width = box->x2 - box->x1 + 1; - int b_height = box->y2 - box->y1 + 1; - - if (!memcmp(&box->c_ul, &box->c_ur, sizeof(color)) && - !memcmp(&box->c_ul, &box->c_ll, sizeof(color)) && - !memcmp(&box->c_ul, &box->c_lr, sizeof(color))) { - solid = 1; - } - - for (y = box->y1; y <= box->y2; y++) { - - int r1, r2, g1, g2, b1, b2, a1, a2; - int h1, h2, h; - u8 opt = 0; - float hr = 0, hg = 0, hb = 0, ha = 0, fr = 0, fg = 0, fb = 0, fa = 0; - - pic = target + (box->x1 + y * fb_var.xres) * bytespp; - - /* Do a nice 2x2 ordered dithering, like it was done in bootsplash; - * this makes the pics in 15/16bpp modes look much nicer; - * the produced pattern is: - * 303030303.. - * 121212121.. - */ - add = (box->x1 & 1); - add ^= (add ^ y) & 1 ? 1 : 3; - - if (solid) { - r = box->c_ul.r; - g = box->c_ul.g; - b = box->c_ul.b; - a = box->c_ul.a; - opt = 1; - } else { - h1 = box->y2 - y; - h2 = y - box->y1; - - if (b_height > 1) - h = b_height -1; - else - h = 1; - - r1 = (h1 * box->c_ul.r + h2 * box->c_ll.r)/h; - r2 = (h1 * box->c_ur.r + h2 * box->c_lr.r)/h; - - g1 = (h1 * box->c_ul.g + h2 * box->c_ll.g)/h; - g2 = (h1 * box->c_ur.g + h2 * box->c_lr.g)/h; - - b1 = (h1 * box->c_ul.b + h2 * box->c_ll.b)/h; - b2 = (h1 * box->c_ur.b + h2 * box->c_lr.b)/h; - - a1 = (h1 * box->c_ul.a + h2 * box->c_ll.a)/h; - a2 = (h1 * box->c_ur.a + h2 * box->c_lr.a)/h; - - if (r1 == r2 && g1 == g2 && b1 == b2 && a1 == a2) { - opt = 1; - } else { - r2 -= r1; - g2 -= g1; - b2 -= b1; - a2 -= a1; - - hr = 1.0/b_width * r2; - hg = 1.0/b_width * g2; - hb = 1.0/b_width * b2; - ha = 1.0/b_width * a2; - } - - r = r1; fr = (float)r1; - g = g1; fg = (float)g1; - b = b1; fb = (float)b1; - a = a1; fa = (float)a1; - } - - for (x = box->x1; x <= box->x2; x++) { - if (!opt) { - fa += ha; - fr += hr; - fg += hg; - fa += hb; - - a = (u8)fa; - b = (u8)fb; - g = (u8)fg; - r = (u8)fr; - } - - put_pixel(a, r, g, b, pic, pic, add); - pic += bytespp; - add ^= 3; - } - } -} - -/* Interpolates two boxes, based on the value of the arg_progress variable. - * This is a strange implementation of a progress bar, introduced by the - * authors of Bootsplash. */ -void interpolate_box(box *a, box *b) -{ - int h = PROGRESS_MAX - arg_progress; - - if (arg_progress == 0) - return; - -#define inter_color(cl1, cl2) \ -{ \ - cl1.r = (cl1.r * h + cl2.r * arg_progress) / PROGRESS_MAX; \ - cl1.g = (cl1.g * h + cl2.g * arg_progress) / PROGRESS_MAX; \ - cl1.b = (cl1.b * h + cl2.b * arg_progress) / PROGRESS_MAX; \ - cl1.a = (cl1.a * h + cl2.a * arg_progress) / PROGRESS_MAX; \ -} - - a->x1 = (a->x1 * h + b->x1 * arg_progress) / PROGRESS_MAX; - a->x2 = (a->x2 * h + b->x2 * arg_progress) / PROGRESS_MAX; - a->y1 = (a->y1 * h + b->y1 * arg_progress) / PROGRESS_MAX; - a->y2 = (a->y2 * h + b->y2 * arg_progress) / PROGRESS_MAX; - - inter_color(a->c_ul, b->c_ul); - inter_color(a->c_ur, b->c_ur); - inter_color(a->c_ll, b->c_ll); - inter_color(a->c_lr, b->c_lr); -} - -char *get_program_output(char *prg, unsigned char origin) -{ - char *buf = malloc(1024); - fd_set rfds; - struct timeval tv; - int pfds[2]; - pid_t pid; - int i; - - if (!buf) - return NULL; - - pipe(pfds); - pid = fork(); - buf[0] = 0; - - if (pid == 0) { - if (origin != FB_SPLASH_IO_ORIG_KERNEL) { - /* Only play with stdout if we are NOT the kernel helper. - * Otherwise, things will break horribly and we'll end up - * with a deadlock. */ - close(1); - } - dup(pfds[1]); - close(pfds[0]); - execlp("sh", "sh", "-c", prg, NULL); - } else { - FD_ZERO(&rfds); - FD_SET(pfds[0], &rfds); - tv.tv_sec = 0; - tv.tv_usec = 250000; - i = select(pfds[0]+1, &rfds, NULL, NULL, &tv); - if (i != -1 && i != 0) { - i = read(pfds[0], buf, 1024); - if (i > 0) - buf[i] = 0; - } - - close(pfds[0]); - close(pfds[1]); - } - - return buf; -} - -char *eval_text(char *txt) -{ - char *p, *t, *ret, *d; - int len, i, subst_len, need_subst; - - i = len = strlen(txt); - p = txt; - - subst_len = progress_text?strlen(progress_text):0; - need_subst = 0; - - while ((t = strstr(p, "$progress")) != NULL) { - len += subst_len; - p = t+1; - need_subst = 1; - } - - ret = malloc(len+1); - - if (!need_subst) { - strcpy(ret, txt); - return ret; - } - - p = txt; - d = ret; - - while ((t = strstr(p, "$progress")) != NULL) { - strncpy(d, p, t - p); - d += (t-p); - - if (t > txt && *(t-1) == '\\') { - *(d-1) = '$'; - p = t+1; - continue; - } - - if (progress_text) - strcpy(d, progress_text); - d += subst_len; - p = t; - p += 9; - - if (*p == '%') - p++; - } - - strcpy(d, p); - - return ret; -} - -void prep_bgnd(u8 *target, u8 *src, int x, int y, int w, int h) -{ - u8 *t, *s; - int j, i; - - t = target + (y * fb_var.xres + x) * bytespp; - s = src + (y * fb_var.xres + x) * bytespp; - j = w * bytespp; - i = fb_var.xres * bytespp; - - for (y = 0; y < h; y++) { - memcpy(t, s, j); - t += i; - s += i; - } -} - -/* Prepares the backgroud underneath objects that will be rendered in - * render_objs() */ -void prep_bgnds(u8 *target, u8 *bgnd, char mode) -{ - item *i; - obj *o; - icon *c; - box *b, *n; - - for (i = objs.head; i != NULL; i = i->next) { - o = (obj*)i->p; - - if (o->type == o_box) { - b = (box*)o->p; - - if (b->attr & BOX_SILENT && mode != 's') - continue; - - if (!(b->attr & BOX_SILENT) && mode != 'v') - continue; - - if ((b->attr & BOX_INTER) && i->next != NULL) { - if (((obj*)i->next->p)->type == o_box) { - n = (box*)((obj*)i->next->p)->p; - prep_bgnd(target, bgnd, n->x1, n->y1, n->x2 - n->x1 + 1, n->y2 - n->y1 + 1); - } - } - } else if (o->type == o_icon && mode == 's') { - c = (icon*)o->p; - - if (c->status == 0) - continue; - - if (!c->img) - continue; - - if (!c->img->picbuf) - continue; - - if (c->img->w > fb_var.xres - c->x || c->img->h > fb_var.yres - c->y) { - continue; - } - - prep_bgnd(target, bgnd, c->x, c->y, c->img->w, c->img->h); - } -#if (defined(CONFIG_TTY_KERNEL) && defined(TARGET_KERNEL)) || (defined(CONFIG_TTF) && !defined(TARGET_KERNEL)) - else if (o->type == o_text) { - text *ct = (text*)o->p; - - if (mode == 's' && !(ct->flags & F_TXT_SILENT)) - continue; - - if (mode == 'v' && !(ct->flags & F_TXT_VERBOSE)) - continue; - - if (!ct->font || !ct->font->font) - continue; - - prep_bgnd(target, bgnd, ct->x, ct->y, fb_var.xres - ct->x, ct->font->font->height); - } -#endif - } - -#if (defined(CONFIG_TTF_KERNEL) && defined(TARGET_KERNEL)) || (!defined(TARGET_KERNEL) && defined(CONFIG_TTF)) - if (mode == 's') { - prep_bgnd(target, bgnd, cf.text_x, cf.text_y, fb_var.xres - cf.text_x, global_font->height); - } -#endif -} - -void render_objs(u8 *target, u8 *bgnd, char mode, unsigned char origin, int progress_only) -{ - item *i; - obj *o; - icon *c; - anim *a; - box tmp, *b, *n; - - if (fb_var.bits_per_pixel == 8) - return; - - if (bgnd) - prep_bgnds(target, bgnd, mode); - - for (i = objs.head; i != NULL; i = i->next) { - o = (obj*)i->p; - - if (o->type == o_box) { - b = (box*)o->p; - - if (progress_only && (b->attr & BOX_NOOVER)) - continue; - - if (b->attr & BOX_SILENT && mode != 's') - continue; - - if (!(b->attr & BOX_SILENT) && mode != 'v') - continue; - - if ((b->attr & BOX_INTER) && i->next != NULL) { - if (((obj*)i->next->p)->type == o_box) { - n = (box*)((obj*)i->next->p)->p; - tmp = *b; - interpolate_box(&tmp, n); - render_box2(&tmp, target); - i = i->next; - } - } else { - render_box2(b, target); - } - } else if (o->type == o_icon && mode == 's') { - if (progress_only) - continue; - - c = (icon*)o->p; - - if (c->status == 0) - continue; - - if (!c->img) - continue; - - if (!c->img->picbuf) - continue; - - if (c->img->w > fb_var.xres - c->x || c->img->h > fb_var.yres - c->y) { - printwarn("Icon %s does not fit on the screen - ignoring it.", c->img->filename); - continue; - } - - render_icon(c, target); - } else if (o->type == o_anim) { - u8 render_it = 0; - - a = (anim*)o->p; - - if (mode == 's' && !(a->flags & F_ANIM_SILENT)) - continue; - - if (mode == 'v' && !(a->flags & F_ANIM_VERBOSE)) - continue; - - if ((a->flags & F_ANIM_METHOD_MASK) == F_ANIM_ONCE) { - if (a->status != F_ANIM_STATUS_DONE) { - switch (mng_render_next(a->mng)) { - case MNG_NOERROR: - a->status = F_ANIM_STATUS_DONE; - break; - case MNG_NEEDTIMERWAIT: - /* FIXME: we should actually wait in this case */ - render_it = 1; - break; - } - } - } else if ((a->flags & F_ANIM_METHOD_MASK) == F_ANIM_LOOP) { - if (!mng_render_next(a->mng)) { - /* FIXME: we should actually wait in this case */ - mng_display_restart(a->mng); - mng_render_next(a->mng); - } - render_it = 1; - } else { /* we're F_ANIM_PROPORTIONAL */ - if (mng_render_proportional(a->mng, arg_progress) == MNG_NEEDTIMERWAIT) - render_it = 1; - } - - if (!progress_only || render_it) - mng_display_next(a->mng, target, a->x, a->y); - } -#if (defined(CONFIG_TTY_KERNEL) && defined(TARGET_KERNEL)) || (defined(CONFIG_TTF) && !defined(TARGET_KERNEL)) - else if (o->type == o_text) { - - text *ct = (text*)o->p; - char *txt; - - if (progress_only && !(ct->flags & F_TXT_EVAL)) - continue; - - if (mode == 's' && !(ct->flags & F_TXT_SILENT)) - continue; - - if (mode == 'v' && !(ct->flags & F_TXT_VERBOSE)) - continue; - - if (!ct->font || !ct->font->font) - continue; - - if (ct->flags & F_TXT_EXEC) { - txt = get_program_output(ct->val, origin); - } else if (ct->flags & F_TXT_EVAL) { - txt = eval_text(ct->val); - } else { - txt = ct->val; - } - - if (txt) { - TTF_Render(target, txt, ct->font->font, ct->style, ct->x, ct->y, ct->col, ct->hotspot); - if ((ct->flags & F_TXT_EXEC) || (ct->flags & F_TXT_EVAL)) - free(txt); - } - } -#endif - } - -#if (defined(CONFIG_TTF_KERNEL) && defined(TARGET_KERNEL)) || (!defined(TARGET_KERNEL) && defined(CONFIG_TTF)) - if (mode == 's' && !progress_only) { - if (!boot_message) - TTF_Render(target, DEFAULT_MESSAGE, global_font, - TTF_STYLE_NORMAL, cf.text_x, cf.text_y, - cf.text_color, F_HS_LEFT | F_HS_TOP); - else { - char *t; - t = eval_text(boot_message); - TTF_Render(target, t, global_font, TTF_STYLE_NORMAL, - cf.text_x, cf.text_y, cf.text_color, - F_HS_LEFT | F_HS_TOP); - free(t); - } - } -#endif -} - diff -Naurp suspend2-userui/fbsplash/splash.h s2-userui-mod/fbsplash/splash.h --- suspend2-userui/fbsplash/splash.h 2006-08-11 01:49:27.000000000 +0200 +++ s2-userui-mod/fbsplash/splash.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,302 +0,0 @@ -#ifndef __SPLASH_H__ -#define __SPLASH_H__ - -#include "config.h" -#include -#include -#include - -#if defined(CONFIG_MNG) && !defined(TARGET_KERNEL) - #include "mng_splash.h" -#endif - -#if !defined(CONFIG_FBSPLASH) - #define FB_SPLASH_IO_ORIG_USER 0 - #define FB_SPLASH_IO_ORIG_KERNEL 1 -#endif - -/* Adjustable settings */ -#define MAX_RECTS 32 -#define MAX_BOXES 256 -#define MAX_ICONS 512 -#define PATH_DEV "/dev" -#define PATH_PROC "/proc" -#define PATH_SYS "/sys" -#define SPLASH_DEV PATH_DEV "/fbsplash" - -#define TTY_SILENT 8 -#define TTY_VERBOSE 1 - -#define DEFAULT_MESSAGE "Initializing the kernel..." -#define DEFAULT_FONT "luxisri.ttf" -#define DEFAULT_THEME "suspend2" -#define TTF_DEFAULT THEME_DIR "/" DEFAULT_FONT - -/* Settings that shouldn't be changed */ -#define PROGRESS_MAX 0xffff - -#define u8 __u8 -#define u16 __u16 -#define u32 __u32 - -#define printerr(args...) fprintf(stderr, ## args); -#define printwarn(args...) fprintf(stderr, ## args); -#define min(a,b) ((a) < (b) ? (a) : (b)) -#define max(a,b) ((a) > (b) ? (a) : (b)) -#define CLAMP(x) ((x) > 255 ? 255 : (x)) -#define DEBUG(x...) - -/* ************************************************************************ - * Lists - * ************************************************************************ */ -typedef struct item { - void *p; - struct item *next; -} item; - -typedef struct { - item *head, *tail; -} list; - -#define list_init(list) { list.head = list.tail = NULL; } - -/* ************************************************************************ - * Enums - * ************************************************************************ */ - -enum ENDIANESS { little, big }; -enum TASK { setpic, init, on, off, setcfg, getcfg, getstate, none, paint, - setmode, getmode, repaint, start_daemon }; -enum ESVC { e_display, e_svc_inact_start, e_svc_inact_stop, e_svc_start, - e_svc_started, e_svc_stop, e_svc_stopped, e_svc_stop_failed, - e_svc_start_failed }; - -/* ************************************************************************ - * Structures - * ************************************************************************ */ - -typedef struct { - char *filename; - int w, h; - u8 *picbuf; -} icon_img; - -typedef struct { - int x, y; - icon_img *img; - char *svc; - enum ESVC type; - u8 status; -} icon; - -typedef struct obj { - enum { o_box, o_icon, o_text, o_anim } type; - void *p; -} obj; - -typedef struct color { - u8 r, g, b, a; -} __attribute__ ((packed)) color; - -struct colorf { - float r, g, b, a; -}; - -typedef struct { - int x1, x2, y1, y2; -} rect; - -#if defined(CONFIG_MNG) && !defined(TARGET_KERNEL) -#define F_ANIM_SILENT 1 -#define F_ANIM_VERBOSE 2 - -#define F_ANIM_METHOD_MASK 12 -#define F_ANIM_ONCE 0 -#define F_ANIM_LOOP 4 -#define F_ANIM_PROPORTIONAL 8 - -#define F_ANIM_STATUS_DONE 1 - -typedef struct { - int x, y; - mng_handle mng; - char *svc; - enum ESVC type; - u8 status; - u8 flags; -} anim; -#endif /* CONFIG_MNG */ - -#define F_TXT_SILENT 1 -#define F_TXT_VERBOSE 2 -#define F_TXT_EXEC 4 -#define F_TXT_EVAL 8 - -#define F_HS_HORIZ_MASK 7 -#define F_HS_VERT_MASK 56 - -#define F_HS_TOP 8 -#define F_HS_VMIDDLE 16 -#define F_HS_BOTTOM 32 - -#define F_HS_LEFT 1 -#define F_HS_HMIDDLE 2 -#define F_HS_RIGHT 4 - -#if (defined(CONFIG_TTY_KERNEL) && defined(TARGET_KERNEL)) || defined(CONFIG_TTF) -#include "ttf.h" -typedef struct { - char *file; - int size; - TTF_Font *font; -} font_e; - -typedef struct { - int x, y; - u8 hotspot; - color col; - u8 flags; - u8 style; - char *val; - font_e *font; -} text; -#endif /* TTF */ - -typedef struct { - int x1, x2, y1, y2; - struct color c_ul, c_ur, c_ll, c_lr; /* upper left, upper right, - lower left, lower right */ - u8 attr; -} box; - -typedef struct truecolor { - u8 r, g, b, a; -} __attribute__ ((packed)) truecolor; - -#define BOX_NOOVER 0x01 -#define BOX_INTER 0x02 -#define BOX_SILENT 0x04 - -struct splash_config { - u8 bg_color; - u16 tx; - u16 ty; - u16 tw; - u16 th; - u16 text_x, text_y; - u16 text_size; - color text_color; - char *text_font; -} __attribute__ ((packed)); - -/* ************************************************************************ - * Functions - * ************************************************************************ */ - -/* common.c */ -void detect_endianess(void); -int get_fb_settings(int fb_num); -char *get_cfg_file(char *theme); -int do_getpic(unsigned char, unsigned char, char); -int do_config(unsigned char); -char *get_filepath(char *path); -void vt_cursor_enable(int fd); -void vt_cursor_disable(int fd); -int open_fb(); -int open_tty(int); -int tty_unset_silent(int fd); -int tty_set_silent(int tty, int fd); - -/* parse.c */ -int parse_cfg(char *cfgfile); -int parse_svc_state(char *t, enum ESVC *state); - -/* dev.c */ -int create_dev(char *fn, char *sys, int flag); -int remove_dev(char *fn, int flag); - -#define open_cr(fd, dev, sysfs, outlabel, flag) \ - create_dev(dev, sysfs, flag); \ - fd = open(dev, O_RDWR); \ - if (fd == -1) { \ - remove_dev(dev, flag); \ - goto outlabel; \ - } - -#define close_del(fd, dev, flag) \ - close(fd); \ - remove_dev(dev, flag); - -/* render.c */ -void render_objs(u8 *target, u8 *bgnd, char mode, unsigned char origin, int progress_only); -inline void put_pixel (u8 a, u8 r, u8 g, u8 b, u8 *src, u8 *dst, u8 add); - -/* image.c */ -int load_images(char mode); -void truecolor2fb (truecolor* data, u8* out, int len, int y, u8 alpha); - -/* cmd.c */ -void cmd_setstate(unsigned int state, unsigned char origin); -void cmd_setpic(struct fb_image *img, unsigned char origin); -void cmd_setcfg(unsigned char origin); -void cmd_getcfg(); - -/* daemon.c */ -void daemon_start(); -void do_paint(u8 *dst, u8 *src); -void do_repaint(u8 *dst, u8 *src); - -/* list.c */ -void list_add(list *l, void *obj); - -/* effects.c */ -void put_img(u8 *dst, u8 *src); -void fade_in(u8 *dst, u8 *image, struct fb_cmap cmap, u8 bgnd, int fd); -void set_directcolor_cmap(int fd); - -extern char *cf_pic; -extern char *cf_silentpic; -extern char *cf_pic256; -extern char *cf_silentpic256; - -extern struct fb_var_screeninfo fb_var; -extern struct fb_fix_screeninfo fb_fix; - -extern enum ENDIANESS endianess; -extern enum TASK arg_task; -extern int arg_fb; -extern int arg_vc; -extern char *arg_theme; -extern char arg_mode; -extern u16 arg_progress; -extern u8 arg_kdmode; - -#ifndef TARGET_KERNEL -extern char *arg_export; -extern u8 theme_loaded; -#endif - -extern char *config_file; - -extern list icons; -extern list objs; -extern list rects; -extern list fonts; - -extern u8 *bg_buffer; -extern int bytespp; - -extern struct fb_image verbose_img; -extern struct fb_image silent_img; - -extern struct splash_config cf; - -/* common.c */ -extern u8 fb_opt; -extern u8 fb_ro, fb_go, fb_bo; -extern u8 fb_rlen, fb_glen, fb_blen; - -extern int fb_fd, fbsplash_fd; -extern char *progress_text; - -#endif /* __SPLASH_H__ */ diff -Naurp suspend2-userui/fbsplash/ttf.c s2-userui-mod/fbsplash/ttf.c --- suspend2-userui/fbsplash/ttf.c 2007-07-26 17:55:58.000000000 +0200 +++ s2-userui-mod/fbsplash/ttf.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,755 +0,0 @@ -/* - * tty.c - support for True Type fonts - * - * TuxOnIce userui adaptations: - * Copyright (C) 2005 Bernard Blackham - * - * Based on the original splashutils code: - * Copyright (C) 2004-2005 Michal Januszewski - * - * Fbtruetype code: - * (w) by stepan@suse.de - * - * Original code comes from SDL_ttf. - * - * This file is subject to the terms and conditions of the GNU General Public - * License v2. See the file COPYING in the main directory of this archive for - * more details. - * - */ - -#ifndef TARGET_KERNEL -#include -#endif -#include -#include -#include -#include - -#include -#include -#include - -#include "splash.h" - -TTF_Font *global_font; -char *boot_message = NULL; - -#define DEFAULT_PTSIZE 18 -#define NUM_GRAYS 256 - -void TTF_RenderUNICODE_Shaded(u8 *target, const unsigned short *text, - TTF_Font* font, int x, int y, color fcol, u8 hotspot); - - -static void Flush_Glyph(c_glyph* glyph); - -static void Flush_Cache(TTF_Font* font) -{ - int i; - int size = sizeof(font->cache) / sizeof(font->cache[0]); - - for(i = 0; i < size; ++i) { - if(font->cache[i].cached) { - Flush_Glyph(&font->cache[i]); - } - - } - if(font->scratch.cached) { - Flush_Glyph(&font->scratch); - } -} - -/* character conversion */ - -/* Macro to convert a character to a Unicode value -- assume already Unicode */ -#define UNICODE(c) c - -/* -static unsigned short *ASCII_to_UNICODE(unsigned short *unicode, const char *text, int len) -{ - int i; - - for (i=0; i < len; ++i) { - unicode[i] = ((const unsigned char *)text)[i]; - } - unicode[i] = 0; - - return unicode; -} -*/ - -#ifdef TARGET_KERNEL -int ceil(float a) -{ - int h = (int)a; - if (a - h >= 0.5) - return h+1; - else - return h; -} -#endif - -static unsigned short *UTF8_to_UNICODE(unsigned short *unicode, const char *utf8, int len) -{ - int i, j; - unsigned short ch; - - for (i=0, j=0; i < len; ++i, ++j) { - ch = ((const unsigned char *)utf8)[i]; - if (ch >= 0xF0) { - ch = (unsigned short)(utf8[i]&0x07) << 18; - ch |= (unsigned short)(utf8[++i]&0x3F) << 12; - ch |= (unsigned short)(utf8[++i]&0x3F) << 6; - ch |= (unsigned short)(utf8[++i]&0x3F); - } else - if (ch >= 0xE0) { - ch = (unsigned short)(utf8[i]&0x3F) << 12; - ch |= (unsigned short)(utf8[++i]&0x3F) << 6; - ch |= (unsigned short)(utf8[++i]&0x3F); - } else - if (ch >= 0xC0) { - ch = (unsigned short)(utf8[i]&0x3F) << 6; - ch |= (unsigned short)(utf8[++i]&0x3F); - } - unicode[j] = ch; - } - unicode[j] = 0; - - return unicode; -} - -/* TTF stuff */ - -static FT_Library library; -static int TTF_initialized = 0; - -int TTF_Init(void) -{ - int status; - FT_Error error; - - status = 0; - error = FT_Init_FreeType(&library); - if (error) { - fprintf(stderr, "Couldn't init FreeType engine %d\n", error); - status = -1; - } else { - TTF_initialized = 1; - } - return status; -} - -void TTF_Quit(void) -{ - if (TTF_initialized) { - FT_Done_FreeType(library); - } - TTF_initialized = 0; -} - -unsigned char*TTF_RenderText_Shaded(u8 *target, const char *text, TTF_Font *font, int x, int y, color col, u8 hotspot) -{ - unsigned short *p, *t, *unicode_text; - int unicode_len; - - /* Copy the Latin-1 text to a UNICODE text buffer */ - unicode_len = strlen(text); - unicode_text = (unsigned short *)malloc((unicode_len+1)*(sizeof*unicode_text)); - - if (unicode_text == NULL) { - printf("Out of memory\n"); - return(NULL); - } - - UTF8_to_UNICODE(unicode_text, text, unicode_len); -// ASCII_to_UNICODE(unicode_text, text, unicode_len); - - for (t = p = unicode_text; *p != 0; p++) { - if (*p == '\n') { - *p = 0; - if (p > t) - TTF_RenderUNICODE_Shaded(target, t, font, x, y, col, hotspot); - y += font->height; - t = p+1; - } - } - - if (*t != 0) { - TTF_RenderUNICODE_Shaded(target, t, font, x, y, col, hotspot); - } - - /* Free the text buffer and return */ - free(unicode_text); - return NULL; -} - -void TTF_CloseFont(TTF_Font* font) -{ - Flush_Cache(font); - FT_Done_Face(font->face); - free(font); -} - -void TTF_SetFontStyle(TTF_Font* font, int style) -{ - font->style = style; - Flush_Cache(font); -} - -TTF_Font* TTF_OpenFontIndex(const char *file, int ptsize, long index) -{ - TTF_Font* font; - FT_Error error; - FT_Face face; - FT_Fixed scale; - - font = (TTF_Font*) malloc(sizeof *font); - if (font == NULL) { - fprintf(stderr, "Out of memory\n"); - return NULL; - } - memset(font, 0, sizeof(*font)); - - /* Open the font and create ancillary data */ - error = FT_New_Face(library, file, 0, &font->face); - - if (error) - error = FT_New_Face(library, TTF_DEFAULT, 0, &font->face); - -// if (error && !strict_font) -// error=FT_New_Memory_Face(library, (const FT_Byte*)luxisri_ttf, LUXISRI_SIZE, 0, &font->face); - - if (error) { - printf("Couldn't load font file: Error %x\n", error); - free(font); - return NULL; - } - - if (index != 0) { - if (font->face->num_faces > index) { - FT_Done_Face(font->face); - error = FT_New_Face(library, file, index, &font->face); - if(error) { - printf("Couldn't get font face: Error %x\n", error); - free(font); - return NULL; - } - } else { - fprintf(stderr, "No such font face: Error %x\n", error); - free(font); - return NULL; - } - } - face = font->face; - - /* Make sure that our font face is scalable (global metrics) */ - if (! FT_IS_SCALABLE(face)) { - fprintf(stderr,"Font face is not scalable\n"); - TTF_CloseFont(font); - return NULL; - } - /* Set the character size and use default DPI (72) */ - error = FT_Set_Char_Size(font->face, 0, ptsize * 64, 0, 0); - if (error) { - fprintf(stderr, "Couldn't set font size\n"); - TTF_CloseFont(font); - return NULL; - } - - /* Get the scalable font metrics for this font */ - scale = face->size->metrics.y_scale; - font->ascent = FT_CEIL(FT_MulFix(face->bbox.yMax, scale)); - font->descent = FT_CEIL(FT_MulFix(face->bbox.yMin, scale)); - font->height = font->ascent - font->descent + /* baseline */ 1; - font->lineskip = FT_CEIL(FT_MulFix(face->height, scale)); - font->underline_offset = FT_FLOOR(FT_MulFix(face->underline_position, scale)); - font->underline_height = FT_FLOOR(FT_MulFix(face->underline_thickness, scale)); - if (font->underline_height < 1) { - font->underline_height = 1; - } - - /* Set the default font style */ - font->style = TTF_STYLE_NORMAL; - font->glyph_overhang = face->size->metrics.y_ppem / 10; - /* x offset = cos(((90.0-12)/360)*2*M_PI), or 12 degree angle */ - font->glyph_italics = 0.207f; - font->glyph_italics *= font->height; - - return font; -} - -TTF_Font* TTF_OpenFont(const char *file, int ptsize) -{ - TTF_Font *a; - - a = TTF_OpenFontIndex(file, ptsize, 0); - - if (a == NULL) { - fprintf(stderr, "Couldn't load %d pt font from %s\n", ptsize, file); - } - - return a; -} - -static void Flush_Glyph(c_glyph* glyph) -{ - glyph->stored = 0; - glyph->index = 0; - if(glyph->bitmap.buffer) { - free(glyph->bitmap.buffer); - glyph->bitmap.buffer = 0; - } - if(glyph->pixmap.buffer) { - free(glyph->pixmap.buffer); - glyph->pixmap.buffer = 0; - } - glyph->cached = 0; -} - -static FT_Error Load_Glyph(TTF_Font* font, unsigned short ch, c_glyph* cached, int want) -{ - FT_Face face; - FT_Error error; - FT_GlyphSlot glyph; - FT_Glyph_Metrics* metrics; - FT_Outline* outline; - - assert(font); - assert(font->face); - - face = font->face; - - /* Load the glyph */ - if (! cached->index) { - cached->index = FT_Get_Char_Index(face, ch); - } - error = FT_Load_Glyph(face, cached->index, FT_LOAD_DEFAULT); - if(error) { - return error; - } - /* Get our glyph shortcuts */ - glyph = face->glyph; - metrics = &glyph->metrics; - outline = &glyph->outline; - - /* Get the glyph metrics if desired */ - if ((want & CACHED_METRICS) && !(cached->stored & CACHED_METRICS)) { - /* Get the bounding box */ - cached->minx = FT_FLOOR(metrics->horiBearingX); - cached->maxx = cached->minx + FT_CEIL(metrics->width); - cached->maxy = FT_FLOOR(metrics->horiBearingY); - cached->miny = cached->maxy - FT_CEIL(metrics->height); - cached->yoffset = font->ascent - cached->maxy; - cached->advance = FT_CEIL(metrics->horiAdvance); - - /* Adjust for bold and italic text */ - if(font->style & TTF_STYLE_BOLD) { - cached->maxx += font->glyph_overhang; - } - if(font->style & TTF_STYLE_ITALIC) { - cached->maxx += (int)ceil(font->glyph_italics); - } - cached->stored |= CACHED_METRICS; - } - - if (((want & CACHED_BITMAP) && !(cached->stored & CACHED_BITMAP)) || - ((want & CACHED_PIXMAP) && !(cached->stored & CACHED_PIXMAP))) { - int mono = (want & CACHED_BITMAP); - int i; - FT_Bitmap* src; - FT_Bitmap* dst; - - /* Handle the italic style */ - if(font->style & TTF_STYLE_ITALIC) { - FT_Matrix shear; - - shear.xx = 1 << 16; - shear.xy = (int) (font->glyph_italics * (1 << 16))/ font->height; - shear.yx = 0; - shear.yy = 1 << 16; - - FT_Outline_Transform(outline, &shear); - } - - /* Render the glyph */ - if (mono) { - error = FT_Render_Glyph(glyph, ft_render_mode_mono); - } else { - error = FT_Render_Glyph(glyph, ft_render_mode_normal); - } - if(error) { - return error; - } - - /* Copy over information to cache */ - src = &glyph->bitmap; - if (mono) { - dst = &cached->bitmap; - } else { - dst = &cached->pixmap; - } - memcpy(dst, src, sizeof(*dst)); - if (mono) { - dst->pitch *= 8; - } - - /* Adjust for bold and italic text */ - if(font->style & TTF_STYLE_BOLD) { - int bump = font->glyph_overhang; - dst->pitch += bump; - dst->width += bump; - } - if(font->style & TTF_STYLE_ITALIC) { - int bump = (int)ceil(font->glyph_italics); - dst->pitch += bump; - dst->width += bump; - } - - if (dst->rows != 0) { - dst->buffer = malloc(dst->pitch * dst->rows); - if(!dst->buffer) { - return FT_Err_Out_Of_Memory; - } - memset(dst->buffer, 0, dst->pitch * dst->rows); - - for(i = 0; i < src->rows; i++) { - int soffset = i * src->pitch; - int doffset = i * dst->pitch; - if (mono) { - unsigned char *srcp = src->buffer + soffset; - unsigned char *dstp = dst->buffer + doffset; - int j; - for (j = 0; j < src->width; j += 8) { - unsigned char ch = *srcp++; - *dstp++ = (ch&0x80) >> 7; - ch <<= 1; - *dstp++ = (ch&0x80) >> 7; - ch <<= 1; - *dstp++ = (ch&0x80) >> 7; - ch <<= 1; - *dstp++ = (ch&0x80) >> 7; - ch <<= 1; - *dstp++ = (ch&0x80) >> 7; - ch <<= 1; - *dstp++ = (ch&0x80) >> 7; - ch <<= 1; - *dstp++ = (ch&0x80) >> 7; - ch <<= 1; - *dstp++ = (ch&0x80) >> 7; - } - } else { - memcpy(dst->buffer+doffset, - src->buffer+soffset,src->pitch); - } - } - } - - /* Handle the bold style */ - if (font->style & TTF_STYLE_BOLD) { - int row; - int col; - int offset; - int pixel; - unsigned char* pixmap; - - /* The pixmap is a little hard, we have to add and clamp */ - for(row = dst->rows - 1; row >= 0; --row) { - pixmap = (unsigned char*) dst->buffer + row * dst->pitch; - for(offset=1; offset <= font->glyph_overhang; ++offset) { - for(col = dst->width - 1; col > 0; --col) { - pixel = (pixmap[col] + pixmap[col-1]); - if(pixel > NUM_GRAYS - 1) { - pixel = NUM_GRAYS - 1; - } - pixmap[col] = (unsigned char) pixel; - } - } - } - } - - /* Mark that we rendered this format */ - if (mono) { - cached->stored |= CACHED_BITMAP; - } else { - cached->stored |= CACHED_PIXMAP; - } - } - - /* We're done, mark this glyph cached */ - cached->cached = ch; - - return 0; -} - -static FT_Error Find_Glyph(TTF_Font* font, unsigned short ch, int want) -{ - int retval = 0; - - if(ch < 256) { - font->current = &font->cache[ch]; - } else { - if (font->scratch.cached != ch) { - Flush_Glyph(&font->scratch); - } - font->current = &font->scratch; - } - if ((font->current->stored & want) != want) { - retval = Load_Glyph(font, ch, font->current, want); - } - return retval; -} - -int TTF_SizeUNICODE(TTF_Font *font, const unsigned short *text, int *w, int *h) -{ - int status; - const unsigned short *ch; - int x, z; - int minx, maxx; - int miny, maxy; - c_glyph *glyph; - FT_Error error; - - /* Initialize everything to 0 */ - if (! TTF_initialized) { - return -1; - } - status = 0; - minx = maxx = 0; - miny = maxy = 0; - - /* Load each character and sum it's bounding box */ - x= 0; - for (ch=text; *ch; ++ch) { - error = Find_Glyph(font, *ch, CACHED_METRICS); - if (err