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
|
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// Copyright(C) 2008 Simon Howard
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// DESCRIPTION:
// SDL emulation of VGA 640x480x4 planar video mode,
// for Hexen startup loading screen.
//
//-----------------------------------------------------------------------------
#include "SDL.h"
#include "string.h"
#include "doomtype.h"
#include "i_timer.h"
// Palette fade-in takes two seconds
#define FADE_TIME 2000
#define HR_SCREENWIDTH 640
#define HR_SCREENHEIGHT 480
static SDL_Surface *hr_surface = NULL;
boolean I_SetVideoModeHR(void)
{
Uint32 flags;
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
return false;
}
flags = SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF;
hr_surface = SDL_SetVideoMode(HR_SCREENWIDTH, HR_SCREENHEIGHT, 8, flags);
if (hr_surface == NULL)
{
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return false;
}
return true;
}
void I_SetWindowTitleHR(char *title)
{
SDL_WM_SetCaption(title, NULL);
}
void I_UnsetVideoModeHR(void)
{
if (hr_surface != NULL)
{
SDL_QuitSubSystem(SDL_INIT_VIDEO);
hr_surface = NULL;
}
}
void I_ClearScreenHR(void)
{
SDL_Rect area = { 0, 0, HR_SCREENWIDTH, HR_SCREENHEIGHT };
SDL_FillRect(hr_surface, &area, 0);
}
void I_SlamBlockHR(int x, int y, int w, int h, const byte *src)
{
const byte *srcptrs[4];
byte srcbits[4];
byte *dest;
int x1, y1;
int i;
int bit;
// Set up source pointers to read from source buffer - each 4-bit
// pixel has its bits split into four sub-buffers
for (i=0; i<4; ++i)
{
srcptrs[i] = src + (i * w * h / 8);
}
if (SDL_LockSurface(hr_surface) < 0)
{
return;
}
// Draw each pixel
bit = 0;
for (y1=y; y1<y+h; ++y1)
{
dest = ((byte *) hr_surface->pixels) + y1 * hr_surface->pitch + x;
for (x1=x; x1<x+w; ++x1)
{
// Get the bits for this pixel
// For each bit, find the byte containing it, shift down
// and mask out the specific bit wanted.
for (i=0; i<4; ++i)
{
srcbits[i] = (srcptrs[i][bit / 8] >> (7 - (bit % 8))) & 0x1;
}
// Reassemble the pixel value
*dest = (srcbits[0] << 0)
| (srcbits[1] << 1)
| (srcbits[2] << 2)
| (srcbits[3] << 3);
// Next pixel!
++dest;
++bit;
}
}
SDL_UnlockSurface(hr_surface);
// Update the region we drew.
//SDL_UpdateRect(hr_surface, x, y, w, h);
SDL_Flip(hr_surface);
}
void I_SlamHR(const byte *buffer)
{
I_SlamBlockHR(0, 0, HR_SCREENWIDTH, HR_SCREENHEIGHT, buffer);
}
void I_InitPaletteHR(void)
{
// ...
}
void I_SetPaletteHR(const byte *palette)
{
SDL_Color sdlpal[16];
int i;
for (i=0; i<16; ++i)
{
sdlpal[i].r = palette[i * 3 + 0] * 4;
sdlpal[i].g = palette[i * 3 + 1] * 4;
sdlpal[i].b = palette[i * 3 + 2] * 4;
}
SDL_SetColors(hr_surface, sdlpal, 0, 16);
}
void I_FadeToPaletteHR(const byte *palette)
{
byte tmppal[16 * 3];
int starttime;
int elapsed;
int i;
starttime = I_GetTimeMS();
for (;;)
{
elapsed = I_GetTimeMS() - starttime;
if (elapsed >= FADE_TIME)
{
break;
}
// Generate the fake palette
for (i=0; i<16 * 3; ++i)
{
tmppal[i] = (palette[i] * elapsed) / FADE_TIME;
}
I_SetPaletteHR(tmppal);
// Sleep a bit
I_Sleep(10);
}
// Set the final palette
I_SetPaletteHR(palette);
}
void I_BlackPaletteHR(void)
{
byte blackpal[16 * 3];
memset(blackpal, 0, sizeof(blackpal));
I_SetPaletteHR(blackpal);
}
|