1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
/*
* effects.c - miscellaneous graphical effects for splashutils
*
* TuxOnIce userui adaptations:
* Copyright (C) 2005 Bernard Blackham <bernard@blackham.com.au>
*
* Based on the original splashutils code:
* Copyright (C) 2004-2005, Michal Januszewski <spock@gentoo.org>
*
* 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#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);
}
|