aboutsummaryrefslogtreecommitdiff
path: root/engines/voyeur/animation.h
blob: 01d4282f927cc14f38214fda4f1febc6c8f3fe5e (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
/* 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.
 *
 */

#ifndef VOYEUR_ANIMATION_H
#define VOYEUR_ANIMATION_H

#include "video/video_decoder.h"
#include "audio/audiostream.h"
#include "audio/mixer.h"
#include "audio/timestamp.h"
#include "common/array.h"
#include "common/list.h"
#include "common/rect.h"
#include "common/stream.h"
#include "voyeur/files.h"

namespace Voyeur {

class VoyeurEngine;

/**
 * Decoder for RL2 videos.
 *
 * Video decoder used in engines:
 *  - voyeur
 */
class RL2Decoder : public Video::VideoDecoder {
private:
	class RL2FileHeader {
	public:
		RL2FileHeader();
		~RL2FileHeader();

		int _channels;
		int _colorCount;
		int _numFrames;
		int _rate;
		int _soundRate;
		int _videoBase;
		int *_frameSoundSizes;

		uint32 _backSize;
		uint32 _signature;
		uint32 *_frameOffsets;

		byte _palette[768];

		void load(Common::SeekableReadStream *stream);
		Common::Rational getFrameRate() const;
		bool isValid() const;

	private:
		uint32 _form;
		uint32 _dataSize;
		int _method;
		int _defSoundSize;
	};

	class SoundFrame {
	public:
		int _offset;
		int _size;

		SoundFrame(int  offset, int size);
	};

	class RL2AudioTrack : public AudioTrack {
	private:
		Audio::Mixer::SoundType _soundType;
		const RL2FileHeader &_header;
		Audio::QueuingAudioStream *_audStream;
	protected:
		Audio::AudioStream *getAudioStream() const;
	public:
		RL2AudioTrack(const RL2FileHeader &header, Common::SeekableReadStream *stream,
			Audio::Mixer::SoundType soundType);
		~RL2AudioTrack();

		Audio::Mixer::SoundType getSoundType() const { return _soundType; }
		int numQueuedStreams() const { return _audStream->numQueuedStreams(); }
		virtual bool isSeekable() const { return true; }
		virtual bool seek(const Audio::Timestamp &time) { return true; }

		void queueSound(Common::SeekableReadStream *stream, int size);
	};

	class RL2VideoTrack : public FixedRateVideoTrack {
	public:
		RL2VideoTrack(const RL2FileHeader &header, RL2AudioTrack *audioTrack, 
			Common::SeekableReadStream *stream);
		~RL2VideoTrack();

		uint16 getWidth() const;
		uint16 getHeight() const;
		Graphics::Surface *getSurface() { return _surface; }
		Graphics::Surface *getBackSurface();
		Graphics::PixelFormat getPixelFormat() const;
		int getCurFrame() const { return _curFrame; }
		int getFrameCount() const { return _header._numFrames; }
		const Graphics::Surface *decodeNextFrame();
		const byte *getPalette() const { _dirtyPalette = false; return _header._palette; }
		int getPaletteCount() const { return _header._colorCount; }
		bool hasDirtyPalette() const { return _dirtyPalette; }
		const Common::List<Common::Rect> *getDirtyRects() const { return &_dirtyRects; }
		void clearDirtyRects() { _dirtyRects.clear(); }
		void copyDirtyRectsToBuffer(uint8 *dst, uint pitch);

		virtual Common::Rational getFrameRate() const { return _header.getFrameRate(); }
		virtual bool isSeekable() const { return true; }
		virtual bool seek(const Audio::Timestamp &time);
	private:
		Common::SeekableReadStream *_fileStream;
		const RL2FileHeader &_header;
		RL2AudioTrack *_audioTrack;
		Graphics::Surface *_surface;
		Graphics::Surface *_backSurface;
		bool _hasBackFrame;

		mutable bool _dirtyPalette;

		bool _initialFrame;
		int _curFrame;
		uint32 _videoBase;
		uint32 *_frameOffsets;

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

		void copyFrame(uint8 *data);
		void rl2DecodeFrameWithTransparency(int screenOffset);
		void rl2DecodeFrameWithoutTransparency(int screenOffset = -1);
		void initBackSurface();
	};

private:
	RL2AudioTrack *_audioTrack;
	RL2VideoTrack *_videoTrack;
	Common::SeekableReadStream *_fileStream;
	Audio::Mixer::SoundType _soundType;
	RL2FileHeader _header;
	int _paletteStart;
	Common::Array<SoundFrame> _soundFrames;
	int _soundFrameNumber;
	const Common::List<Common::Rect> *getDirtyRects() const;

	void clearDirtyRects();
	void copyDirtyRectsToBuffer(uint8 *dst, uint pitch);
	int getPaletteStart() const { return _paletteStart; }
	const RL2FileHeader &getHeader() { return _header; }
	virtual void readNextPacket();
	virtual bool seekIntern(const Audio::Timestamp &time);

public:
	RL2Decoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType);
	virtual ~RL2Decoder();

	virtual void close();

	bool loadStream(Common::SeekableReadStream *stream);
	bool loadFile(const Common::String &file, bool palFlag = false);
	bool loadVideo(int videoId);
	int getPaletteCount() const { return _header._colorCount; }

	/**
	 * Play back a given Voyeur RL2 video
	 * @param vm			Engine reference
	 * @param resourceOffset Starting resource to use for frame pictures
	 * @param frames		Optional frame numbers resource for when to apply image data
	 * @param imgPos		Position to draw image data
	 */
	void play(VoyeurEngine *vm, int resourceOffset = 0, byte *frames = NULL, byte *imgPos = NULL);
	RL2VideoTrack *getVideoTrack() { return _videoTrack; }
	RL2AudioTrack *getAudioTrack() { return _audioTrack; }
};

} // End of namespace Voyeur

#endif /* VOYEUR_ANIMATION_H */