- Fix memory leak from r42218 ;0)
[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 MmHeapFree(PaletteColors);
95 }
96
97 VOID VideoFadeOut(ULONG ColorCount)
98 {
99 ULONG Index;
100 ULONG Color;
101 UCHAR Red;
102 UCHAR Green;
103 UCHAR Blue;
104
105 for (Index=0; Index<RGB_MAX; Index++)
106 {
107 for (Color=0; Color<ColorCount; Color++)
108 {
109 if ((Color % RGB_MAX_PER_ITERATION) == 0)
110 {
111 MachVideoSync();
112 }
113
114 MachVideoGetPaletteColor(Color, &Red, &Green, &Blue);
115
116 if (Red > 0)
117 {
118 Red--;
119 }
120 if (Green > 0)
121 {
122 Green--;
123 }
124 if (Blue > 0)
125 {
126 Blue--;
127 }
128
129 MachVideoSetPaletteColor(Color, Red, Green, Blue);
130 }
131 }
132 }