aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/video.h
blob: c71a18daa65791b8c531d24fd99a7cd735070841 (plain)
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#ifndef GOB_VIDEO_H
#define GOB_VIDEO_H

#include "common/list.h"
#include "common/rect.h"
#include "common/ptr.h"

#include "gob/gob.h"

namespace Graphics {
	class PaletteLUT;
}

namespace Gob {

// Some Surfaces are simultaneous in Draw::spritesArray and discrete
// variables, so if in doubt you should use a SurfaceDescPtr shared
// pointer object to refer to any SurfaceDesc.
class SurfaceDesc {
public:
	int16 _vidMode;

	int16 getWidth() const { return _width; }
	int16 getHeight() const { return _height; }
	byte *getVidMem() { return _vidMem; }
	const byte *getVidMem() const { return _vidMem; }
	bool hasOwnVidMem() const { return _ownVidMem; }

	void setVidMem(byte *vidMem);
	void resize(int16 width, int16 height);
	void swap(SurfaceDesc &surf);

	SurfaceDesc(int16 vidMode, int16 width, int16 height, byte *vidMem = 0);
	~SurfaceDesc() { if (_ownVidMem) delete[] _vidMem; }

private:
	int16 _width;
	int16 _height;
	byte *_vidMem;
	bool _ownVidMem;
};

typedef Common::SharedPtr<SurfaceDesc> SurfaceDescPtr;


class Video {
public:
	struct FontDesc {
		byte *dataPtr;
		int8 itemWidth;
		int8 itemHeight;
		uint8 startItem;
		uint8 endItem;
		int8 itemSize;
		int8 bitWidth;
		byte *extraData;
		FontDesc() : dataPtr(0), itemWidth(0), itemHeight(0), startItem(0),
		             endItem(0), itemSize(0), bitWidth(0) {}
		~FontDesc() {
			if (dataPtr)
				delete[] (dataPtr - 4);
		}
	};

#define GDR_VERSION	4

#define PRIMARY_SURFACE		0x80
#define RETURN_PRIMARY		0x01
#define DISABLE_SPR_ALLOC	0x20
#define SCUMMVM_CURSOR		0x100

#include "common/pack-start.h"	// START STRUCT PACKING

	struct Color {
		byte red;
		byte green;
		byte blue;
	} PACKED_STRUCT;

#include "common/pack-end.h"	// END STRUCT PACKING

	struct PalDesc {
		Color *vgaPal;
		int16 *unused1;
		int16 *unused2;
		PalDesc() : vgaPal(0), unused1(0), unused2(0) {}
	};

	bool _doRangeClamp;

	int16 _surfWidth;
	int16 _surfHeight;

	int16 _scrollOffsetX;
	int16 _scrollOffsetY;

	SurfaceDescPtr _splitSurf;
	int16 _splitHeight1;
	int16 _splitHeight2;
	int16 _splitStart;

	int16 _screenDeltaX;
	int16 _screenDeltaY;

	Graphics::PaletteLUT *_palLUT;

	void freeDriver();
	void initPrimary(int16 mode);
	SurfaceDescPtr initSurfDesc(int16 vidMode, int16 width,
			int16 height, int16 flags);

	void setSize(bool defaultTo1XScaler);

	void clearScreen();
	void retrace(bool mouse = true);
	void waitRetrace(bool mouse = true);
	void sparseRetrace(int max);

	void putPixel(int16 x, int16 y, int16 color, SurfaceDesc &dest);
	virtual void fillRect(SurfaceDesc &dest, int16 left, int16 top,
			int16 right, int16 bottom, int16 color);
	void drawLine(SurfaceDesc &dest, int16 x0, int16 y0, int16 x1, int16 y1,
				  int16 color);
	void drawCircle(SurfaceDesc &dest, int16 x0, int16 y0,
			int16 radius, int16 color);
	void clearSurf(SurfaceDesc &dest);
	void drawSprite(SurfaceDesc &source, SurfaceDesc &dest,
			int16 left, int16 top, int16 right, int16 bottom,
			int16 x, int16 y, int16 transp);
	void drawSpriteDouble(SurfaceDesc &source, SurfaceDesc &dest,
	    int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp);
	void drawLetter(int16 item, int16 x, int16 y, FontDesc *fontDesc,
			int16 color1, int16 color2, int16 transp, SurfaceDesc &dest);
	void drawPackedSprite(byte *sprBuf, int16 width, int16 height,
			int16 x, int16 y, int16 transp, SurfaceDesc &dest);
	void drawPackedSprite(const char *path, SurfaceDesc &dest,
			int width = 320);

	void setPalColor(byte *pal, byte red, byte green, byte blue) {
		pal[0] = red << 2;
		pal[1] = green << 2;
		pal[2] = blue << 2;
		pal[3] = 0;
	}
	void setPalColor(byte *pal, Color &color) {
		setPalColor(pal, color.red, color.green, color.blue);
	}
	void setPalElem(int16 index, char red, char green, char blue,
			int16 unused, int16 vidMode);
	void setPalette(PalDesc *palDesc);
	void setFullPalette(PalDesc *palDesc);
	void setPalette(Color *palette);

	void dirtyRectsClear();
	void dirtyRectsAll();
	void dirtyRectsAdd(int16 left, int16 top, int16 right, int16 bottom);
	void dirtyRectsApply(int left, int top, int width, int height, int x, int y);

	virtual char spriteUncompressor(byte *sprBuf, int16 srcWidth,
			int16 srcHeight, int16 x, int16 y, int16 transp,
			SurfaceDesc &destDesc) = 0;

	virtual void init() {}

	virtual void setPrePalette() { }

	Video(class GobEngine *vm);
	virtual ~Video();

protected:
	class VideoDriver *_videoDriver;

	bool _dirtyAll;
	Common::List<Common::Rect> _dirtyRects;

	int _curSparse;
	uint32 _lastSparse;

	GobEngine *_vm;

	char initDriver(int16 vidMode);

	void initOSD();
	void drawOSDText(const char *text);
};

class Video_v1 : public Video {
public:
	virtual char spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight,
			int16 x, int16 y, int16 transp, SurfaceDesc &destDesc);

	Video_v1(GobEngine *vm);
	virtual ~Video_v1() {}
};

class Video_v2 : public Video_v1 {
public:
	virtual char spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight,
			int16 x, int16 y, int16 transp, SurfaceDesc &destDesc);

	Video_v2(GobEngine *vm);
	virtual ~Video_v2() {}
};

class Video_v6 : public Video_v2 {
public:
	virtual char spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight,
			int16 x, int16 y, int16 transp, SurfaceDesc &destDesc);

	virtual void fillRect(SurfaceDesc &dest, int16 left, int16 top,
			int16 right, int16 bottom, int16 color);

	virtual void init();

	virtual void setPrePalette();

	Video_v6(GobEngine *vm);
	virtual ~Video_v6() {}

private:
	static const byte _ditherPalette[768];

	void buildPalLUT();

	void shadeRect(SurfaceDesc &dest,
			int16 left, int16 top, int16 right, int16 bottom, byte color, byte strength);

	void drawPacked(const byte *sprBuf, int16 x, int16 y, SurfaceDesc &surfDesc);
	void drawYUVData(const byte *srcData, SurfaceDesc &destDesc,
			int16 width, int16 height, int16 x, int16 y);
	void drawYUV(SurfaceDesc &destDesc, int16 x, int16 y,
			int16 dataWidth, int16 dataHeight, int16 width, int16 height,
			const byte *dataY, const byte *dataU, const byte *dataV);
};

class VideoDriver {
public:
	VideoDriver() {}
	virtual ~VideoDriver() {}
	virtual void drawSprite(SurfaceDesc &source, SurfaceDesc &dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) = 0;
	virtual void drawSpriteDouble(SurfaceDesc &source, SurfaceDesc &dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) = 0;
	virtual void fillRect(SurfaceDesc &dest, int16 left, int16 top, int16 right, int16 bottom, byte color) = 0;
	virtual void putPixel(int16 x, int16 y, byte color, SurfaceDesc &dest) = 0;
	virtual void drawLetter(unsigned char item, int16 x, int16 y, Video::FontDesc *fontDesc, byte color1, byte color2, byte transp, SurfaceDesc &dest) = 0;
	virtual void drawLine(SurfaceDesc &dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color) = 0;
	virtual void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, SurfaceDesc &dest) = 0;
};

} // End of namespace Gob

#endif // GOB_VIDEO_H