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
|
/* 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.
*
*/
#include "access/video.h"
#include "access/access.h"
namespace Access {
VideoPlayer::VideoPlayer(AccessEngine *vm) : Manager(vm) {
_vidSurface = nullptr;
_videoFrame = 0;
_soundFlag = false;
_soundFrame = 0;
_videoData = nullptr;
}
VideoPlayer::~VideoPlayer() {
closeVideo();
}
void VideoPlayer::setVideo(ASurface *vidSurface, const Common::Point &pt, const FileIdent &videoFile, int rate) {
_vidSurface = vidSurface;
vidSurface->_orgX1 = pt.x;
vidSurface->_orgY1 = pt.y;
_vm->_timers[31]._timer = rate;
_vm->_timers[31]._initTm = rate;
// Open up video stream
_videoData = _vm->_files->loadFile(videoFile);
// Load in header
_header._frameCount = _videoData->_stream->readUint16LE();
_header._width = _videoData->_stream->readUint16LE();
_header._height = _videoData->_stream->readUint16LE();
_videoData->_stream->skip(1);
_header._flags = (VideoFlags)_videoData->_stream->readByte();
_startCoord = (byte *)vidSurface->getBasePtr(pt.x, pt.y);
_frameCount = _header._frameCount - 2;
_xCount = _header._width;
_scanCount = _header._height;
_videoFrame = 0;
getFrame();
if (_header._flags == VIDEOFLAG_BG) {
// Draw the background
for (int y = 0; y < _scanCount; ++y) {
byte *pDest = (byte *)vidSurface->getBasePtr(pt.x, pt.y + y);
_videoData->_stream->read(pDest, _xCount);
}
if (vidSurface == _vm->_screen)
_vm->_newRects.push_back(Common::Rect(pt.x, pt.y, pt.x + _xCount, pt.y + _scanCount));
getFrame();
}
_videoEnd = false;
}
void VideoPlayer::closeVideo() {
delete _videoData;
_videoData = nullptr;
}
void VideoPlayer::getFrame() {
_frameSize = _videoData->_stream->readUint16LE();
}
void VideoPlayer::playVideo() {
if (_vm->_timers[31]._flag)
return;
++_vm->_timers[31]._flag;
byte *pDest = _startCoord;
byte *pLine = _startCoord;
uint32 frameEnd = _videoData->_stream->pos() + _frameSize;
while ((uint32)_videoData->_stream->pos() < frameEnd) {
int count = _videoData->_stream->readByte();
if (count & 0x80) {
count &= 0x7f;
// Skip count number of pixels
// Loop across lines if necessary
while (count >= (pLine + _xCount - pDest)) {
count -= (pLine + _xCount - pDest);
pLine += _vidSurface->pitch;
pDest = pLine;
}
// Skip any remaining pixels in the new line
pDest += count;
} else {
// Read count number of pixels
// Load across lines if necessary
while (count >= (pLine + _xCount - pDest)) {
int lineCount = (pLine + _xCount - pDest);
_videoData->_stream->read(pDest, lineCount);
count -= lineCount;
pLine += _vidSurface->pitch;
pDest = pLine;
}
// Load remainder of pixels on line
if (count > 0) {
_videoData->_stream->read(pDest, count);
pDest += count;
}
}
}
getFrame();
if (++_videoFrame == _frameCount) {
closeVideo();
_videoEnd = true;
}
}
void VideoPlayer::copyVideo() {
_vm->_player->calcPlayer();
Common::Rect r = Common::Rect(_vm->_vidX - _vm->_screen->_bufferStart.x,
_vm->_vidY - _vm->_screen->_bufferStart.y,
_vm->_vidX - _vm->_screen->_bufferStart.x + _header._width,
_vm->_vidY - _vm->_screen->_bufferStart.y + _header._height);
if (!_vm->_screen->clip(r))
return;
_vm->_newRects.push_back(r);
int vh = _header._height;
int vw = _header._width;
int destIdx = _vm->_vidX - _vm->_screen->_bufferStart.x;
int srcIdx = _vm->_screen->_leftSkip;
for (int i = 0; i < _vm->_screen->_topSkip; i++)
destIdx += 160;
const byte *srcP = (const byte *)_vm->_vidBuf.getPixels() + srcIdx;
byte *destP = (byte *)_vm->_buffer2.getPixels() + destIdx;
for (int i = 0; i < vh; i++) {
Common::copy(srcP, srcP + vw, destP);
srcP += _vm->_vidBuf.pitch;
destP += _vm->_buffer2.pitch;
}
}
} // End of namespace Access
|