[FREELDR] Move files where they are only used.
[reactos.git] / boot / freeldr / freeldr / ui / video.c
1 /*
2 * PROJECT: FreeLoader
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: UI Video helpers for special effects.
5 * COPYRIGHT: Copyright 1998-2003 Brian Palmer <brianp@sginet.com>
6 */
7
8 #ifndef _M_ARM
9 #include <freeldr.h>
10
11 #define RGB_MAX 64
12 #define RGB_MAX_PER_ITERATION 64
13 #define TAG_PALETTE_COLORS 'claP'
14
15 static PVOID VideoOffScreenBuffer = NULL;
16
17 PVOID VideoAllocateOffScreenBuffer(VOID)
18 {
19 ULONG BufferSize;
20
21 if (VideoOffScreenBuffer != NULL)
22 {
23 MmFreeMemory(VideoOffScreenBuffer);
24 VideoOffScreenBuffer = NULL;
25 }
26
27 BufferSize = MachVideoGetBufferSize();
28
29 VideoOffScreenBuffer = MmAllocateMemoryWithType(BufferSize, LoaderFirmwareTemporary);
30
31 return VideoOffScreenBuffer;
32 }
33
34 VOID VideoCopyOffScreenBufferToVRAM(VOID)
35 {
36 MachVideoCopyOffScreenBufferToVRAM(VideoOffScreenBuffer);
37 }
38
39
40 VOID VideoSavePaletteState(PPALETTE_ENTRY Palette, ULONG ColorCount)
41 {
42 ULONG Color;
43
44 for (Color = 0; Color < ColorCount; Color++)
45 {
46 MachVideoGetPaletteColor((UCHAR)Color, &Palette[Color].Red, &Palette[Color].Green, &Palette[Color].Blue);
47 }
48 }
49
50 VOID VideoRestorePaletteState(PPALETTE_ENTRY Palette, ULONG ColorCount)
51 {
52 ULONG Color;
53
54 MachVideoSync();
55
56 for (Color = 0; Color < ColorCount; Color++)
57 {
58 MachVideoSetPaletteColor((UCHAR)Color, Palette[Color].Red, Palette[Color].Green, Palette[Color].Blue);
59 }
60 }
61
62
63 VOID VideoSetAllColorsToBlack(ULONG ColorCount)
64 {
65 UCHAR Color;
66
67 MachVideoSync();
68
69 for (Color = 0; Color < ColorCount; Color++)
70 {
71 MachVideoSetPaletteColor(Color, 0, 0, 0);
72 }
73 }
74
75 VOID VideoFadeIn(PPALETTE_ENTRY Palette, ULONG ColorCount)
76 {
77 ULONG Index;
78 UCHAR Color;
79 PPALETTE_ENTRY PaletteColors;
80
81 PaletteColors = FrLdrTempAlloc(sizeof(PALETTE_ENTRY) * ColorCount, TAG_PALETTE_COLORS);
82 if (!PaletteColors) return;
83
84 for (Index = 0; Index < RGB_MAX; Index++)
85 {
86 for (Color = 0; Color < ColorCount; Color++)
87 {
88 MachVideoGetPaletteColor(Color, &PaletteColors[Color].Red, &PaletteColors[Color].Green, &PaletteColors[Color].Blue);
89
90 // Increment each color so it approaches its real value
91 if (PaletteColors[Color].Red < Palette[Color].Red)
92 {
93 PaletteColors[Color].Red++;
94 }
95 if (PaletteColors[Color].Green < Palette[Color].Green)
96 {
97 PaletteColors[Color].Green++;
98 }
99 if (PaletteColors[Color].Blue < Palette[Color].Blue)
100 {
101 PaletteColors[Color].Blue++;
102 }
103
104 // Make sure we haven't exceeded the real value
105 if (PaletteColors[Color].Red > Palette[Color].Red)
106 {
107 PaletteColors[Color].Red = Palette[Color].Red;
108 }
109 if (PaletteColors[Color].Green > Palette[Color].Green)
110 {
111 PaletteColors[Color].Green = Palette[Color].Green;
112 }
113 if (PaletteColors[Color].Blue > Palette[Color].Blue)
114 {
115 PaletteColors[Color].Blue = Palette[Color].Blue;
116 }
117 }
118
119 // Set the colors
120 for (Color = 0; Color < ColorCount; Color++)
121 {
122 if ((Color % RGB_MAX_PER_ITERATION) == 0)
123 {
124 MachVideoSync();
125 }
126
127 MachVideoSetPaletteColor(Color, PaletteColors[Color].Red, PaletteColors[Color].Green, PaletteColors[Color].Blue);
128 }
129 }
130
131 FrLdrTempFree(PaletteColors, TAG_PALETTE_COLORS);
132 }
133
134 VOID VideoFadeOut(ULONG ColorCount)
135 {
136 ULONG Index;
137 UCHAR Color;
138 UCHAR Red;
139 UCHAR Green;
140 UCHAR Blue;
141
142 for (Index = 0; Index < RGB_MAX; Index++)
143 {
144 for (Color = 0; Color < ColorCount; Color++)
145 {
146 if ((Color % RGB_MAX_PER_ITERATION) == 0)
147 {
148 MachVideoSync();
149 }
150
151 MachVideoGetPaletteColor(Color, &Red, &Green, &Blue);
152
153 if (Red > 0)
154 {
155 Red--;
156 }
157 if (Green > 0)
158 {
159 Green--;
160 }
161 if (Blue > 0)
162 {
163 Blue--;
164 }
165
166 MachVideoSetPaletteColor(Color, Red, Green, Blue);
167 }
168 }
169 }
170
171 #endif