3f4bbe048abe5cd9065fb9d59998ada1b6e15244
[reactos.git] / reactos / boot / freeldr / freeldr / video / fade.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <freeldr.h>
21
22 #define RGB_MAX 64
23 #define RGB_MAX_PER_ITERATION 64
24
25 VOID VideoSetAllColorsToBlack(ULONG ColorCount)
26 {
27 ULONG Color;
28
29 MachVideoSync();
30
31 for (Color=0; Color<ColorCount; Color++)
32 {
33 MachVideoSetPaletteColor(Color, 0, 0, 0);
34 }
35 }
36
37 VOID VideoFadeIn(PPALETTE_ENTRY Palette, ULONG ColorCount)
38 {
39 ULONG Index;
40 ULONG Color;
41 PPALETTE_ENTRY PaletteColors;
42
43 PaletteColors = MmHeapAlloc(sizeof(PALETTE_ENTRY) * ColorCount);
44 if (!PaletteColors) return;
45
46 for (Index=0; Index<RGB_MAX; Index++)
47 {
48
49 for (Color=0; Color<ColorCount; Color++)
50 {
51 MachVideoGetPaletteColor(Color, &PaletteColors[Color].Red, &PaletteColors[Color].Green, &PaletteColors[Color].Blue);
52
53 // Increment each color so it approaches its real value
54 if (PaletteColors[Color].Red < Palette[Color].Red)
55 {
56 PaletteColors[Color].Red++;
57 }
58 if (PaletteColors[Color].Green < Palette[Color].Green)
59 {
60 PaletteColors[Color].Green++;
61 }
62 if (PaletteColors[Color].Blue < Palette[Color].Blue)
63 {
64 PaletteColors[Color].Blue++;
65 }
66
67 // Make sure we haven't exceeded the real value
68 if (PaletteColors[Color].Red > Palette[Color].Red)
69 {
70 PaletteColors[Color].Red = Palette[Color].Red;
71 }
72 if (PaletteColors[Color].Green > Palette[Color].Green)
73 {
74 PaletteColors[Color].Green = Palette[Color].Green;
75 }
76 if (PaletteColors[Color].Blue > Palette[Color].Blue)
77 {
78 PaletteColors[Color].Blue = Palette[Color].Blue;
79 }
80 }
81
82 // Set the colors
83 for (Color=0; Color<ColorCount; Color++)
84 {
85 if ((Color % RGB_MAX_PER_ITERATION) == 0)
86 {
87 MachVideoSync();
88 }
89
90 MachVideoSetPaletteColor(Color, PaletteColors[Color].Red, PaletteColors[Color].Green, PaletteColors[Color].Blue);
91 }
92 }
93 }
94
95 VOID VideoFadeOut(ULONG ColorCount)
96 {
97 ULONG Index;
98 ULONG Color;
99 UCHAR Red;
100 UCHAR Green;
101 UCHAR Blue;
102
103 for (Index=0; Index<RGB_MAX; Index++)
104 {
105 for (Color=0; Color<ColorCount; Color++)
106 {
107 if ((Color % RGB_MAX_PER_ITERATION) == 0)
108 {
109 MachVideoSync();
110 }
111
112 MachVideoGetPaletteColor(Color, &Red, &Green, &Blue);
113
114 if (Red > 0)
115 {
116 Red--;
117 }
118 if (Green > 0)
119 {
120 Green--;
121 }
122 if (Blue > 0)
123 {
124 Blue--;
125 }
126
127 MachVideoSetPaletteColor(Color, Red, Green, Blue);
128 }
129 }
130 }