2 * effects.c - miscellaneous graphical effects for splashutils
4 * Copyright (C) 2004-2005, Michal Januszewski <spock@gentoo.org>
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License v2. See the file COPYING in the main directory of this archive for
16 #include <sys/ioctl.h>
20 #define FADEIN_STEPS 64
21 #define FADEIN_STEPS_DC 256
24 * Copy the data from the background buffer to the framebuffer.
25 * The bg buffer dimensions need not match those of the current
28 void put_img(stheme_t
*theme
, u8
*dst
, u8
*src
)
33 to
+= theme
->xmarg
* fbd
.bytespp
+ theme
->ymarg
* fbd
.fix
.line_length
;
34 i
= theme
->xres
* fbd
.bytespp
;
36 for (y
= 0; y
< theme
->yres
; y
++) {
37 memcpy(to
, src
+ i
*y
, i
);
38 to
+= fbd
.fix
.line_length
;
42 void paint_rect(stheme_t
*theme
, u8
*dst
, u8
*src
, int x1
, int y1
, int x2
, int y2
)
47 j
= (x2
- x1
+ 1) * fbd
.bytespp
;
48 for (y
= y1
; y
<= y2
; y
++) {
49 to
= dst
+ (y
+ theme
->ymarg
) * fbd
.fix
.line_length
+ (x1
+ theme
->xmarg
) * fbd
.bytespp
;
50 memcpy(to
, src
+ (y
* theme
->xres
+ x1
) * fbd
.bytespp
, j
);
54 void paint_img(stheme_t
*theme
, u8
*dst
, u8
*src
)
58 for (i
= theme
->blit
.head
; i
!= NULL
;) {
60 paint_rect(theme
, dst
, src
, re
->x1
, re
->y1
, re
->x2
, re
->y2
);
68 list_init(theme
->blit
);
72 * @type = 0 (fadein) or 1 (fadeout)
74 void fade_directcolor(stheme_t
*theme
, u8
*dst
, u8
*image
, int fd
, char type
)
79 len
= min(min(fbd
.var
.red
.length
, fbd
.var
.green
.length
), fbd
.var
.blue
.length
);
82 cmap
.len
= (1 << len
);
84 cmap
.red
= malloc(2 * 256 * 3);
88 cmap
.green
= cmap
.red
+ 256;
89 cmap
.blue
= cmap
.green
+ 256;
91 for (i
= 0; i
< cmap
.len
; i
++) {
92 cmap
.red
[i
] = cmap
.green
[i
] = cmap
.blue
[i
] = 0;
95 ioctl(fd
, FBIOPUTCMAP
, &cmap
);
96 put_img(theme
, dst
, image
);
98 for (step
= 1; step
< FADEIN_STEPS_DC
+1; step
++) {
99 for (i
= 0; i
< cmap
.len
; i
++) {
101 cmap
.red
[i
] = cmap
.green
[i
] = cmap
.blue
[i
] = (0xffff * i
* (FADEIN_STEPS_DC
+1-step
))/
102 ((cmap
.len
-1)*FADEIN_STEPS_DC
);
104 cmap
.red
[i
] = cmap
.green
[i
] = cmap
.blue
[i
] = (0xffff * i
* step
)/((cmap
.len
-1)*FADEIN_STEPS_DC
);
106 ioctl(fd
, FBIOPUTCMAP
, &cmap
);
112 * @type = 0 (fadein) or 1 (fadeout)
114 void fade_truecolor(stheme_t
*theme
, u8
*dst
, u8
*image
, char type
)
116 int rlen
, glen
, blen
;
117 int i
, step
, h
, x
, y
;
119 int r
, g
, b
, rt
, gt
, bt
;
121 int clut
[256][FADEIN_STEPS
];
123 rlen
= fbd
.var
.red
.length
;
124 glen
= fbd
.var
.green
.length
;
125 blen
= fbd
.var
.blue
.length
;
131 t
= malloc(theme
->xres
* theme
->yres
* 3);
133 put_img(theme
, dst
, image
);
139 /* Decode the image into a table where each color component
140 * takes exatly one byte */
141 for (i
= 0; i
< theme
->xres
* theme
->yres
; i
++) {
143 if (fbd
.bytespp
== 2) {
145 } else if (fbd
.bytespp
== 3) {
146 h
= *(u32
*)pic
& 0xffffff;
153 r
= ((h
>> fbd
.var
.red
.offset
& ((1 << rlen
)-1)) << rl8
);
154 g
= ((h
>> fbd
.var
.green
.offset
& ((1 << glen
)-1)) << gl8
);
155 b
= ((h
>> fbd
.var
.blue
.offset
& ((1 << blen
)-1)) << bl8
);
162 /* Compute the color look-up table */
163 for (step
= 0; step
< FADEIN_STEPS
; step
++) {
164 for (i
= 0; i
< 256; i
++) {
166 clut
[i
][step
] = (FADEIN_STEPS
-1-step
) * i
/ FADEIN_STEPS
;
168 clut
[i
][step
] = (step
+1) * i
/ FADEIN_STEPS
;
173 memset(dst
, 0, fbd
.var
.yres
* fbd
.fix
.line_length
);
175 for (step
= 0; step
< FADEIN_STEPS
; step
++) {
177 pic
= dst
+ fbd
.fix
.line_length
* theme
->ymarg
+ theme
->xmarg
* fbd
.bytespp
;
180 for (y
= 0; y
< theme
->yres
; y
++) {
182 for (x
= 0; x
< theme
->xres
; x
++) {
192 if (fbd
.bytespp
== 2) {
198 h
= (rt
<< fbd
.var
.red
.offset
) |
199 (gt
<< fbd
.var
.green
.offset
) |
200 (bt
<< fbd
.var
.blue
.offset
);
202 if (fbd
.bytespp
== 2) {
205 } else if (fbd
.bytespp
== 3) {
206 if (endianess
== little
) {
207 *(u16
*)pic
= h
& 0xffff;
208 pic
[2] = (h
>> 16) & 0xff;
210 *(u16
*)pic
= (h
>> 8) & 0xffff;
214 } else if (fbd
.bytespp
== 4) {
220 pic
+= fbd
.fix
.line_length
- theme
->xres
* fbd
.bytespp
;
227 void fade(stheme_t
*theme
, u8
*dst
, u8
*image
, struct fb_cmap cmap
, u8 bgnd
, int fd
, char type
)
234 /* FIXME: We need to handle 8bpp modes */
236 put_img(theme
, dst
, image
);
240 if (fbd
.fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
241 fade_directcolor(theme
, dst
, image
, fd
, type
);
243 fade_truecolor(theme
, dst
, image
, type
);