Video timing should now be right as well.
[scummvm-innocent.git] / engines / innocent / movie.cpp
blob82e8fb68b59ab11b86f1cfb3a16cd4f590dc6507
1 #include "innocent/movie.h"
3 #include "common/file.h"
5 #include "innocent/debug.h"
6 #include "innocent/graphics.h"
7 #include "innocent/innocent.h"
8 #include "innocent/resources.h"
10 namespace Innocent {
13 Movie *Movie::fromFile(const char *name) {
14 Common::File *f = new Common::File;
15 f->open(name);
16 return new Movie(f);
19 Movie::Movie(Common::ReadStream *s) : _f(s) {}
21 Movie::~Movie() {
22 delete _f;
25 void Movie::setFrameDelay(uint jiffies) {
26 _delay = jiffies;
29 void Movie::play() {
30 _s.create(320, 200, 1);
32 debugC(4, kDebugLevelGraphics, "creating movie");
33 while (findKeyFrame()) {
34 loadKeyFrame();
36 setPalette();
37 showFrame();
39 while (_iFrames) {
40 debugC(3, kDebugLevelGraphics, "got %d iframes", _iFrames);
41 loadIFrame();
42 showFrame();
43 delay();
44 if (Eng.escapePressed())
45 return;
50 bool Movie::findKeyFrame() {
51 (void) _f->readUint32LE(); // size of block, we don't want that
52 _iFrames = _f->readUint16LE();
53 return !_f->eos();
56 void Movie::loadKeyFrame() {
57 (void) _f->readUint16LE(); // no idea what that is
59 uint16 w, h;
60 w = _f->readUint16LE();
61 h = _f->readUint16LE();
62 assert (w == 320 && h == 200);
64 Resources::decodeImage(_f, reinterpret_cast<byte *>(_s.pixels), w * h);
66 (void) _f->readByte();
67 Resources::readPalette(_f, _pal);
68 _iFrames--;
71 void Movie::loadIFrame() {
72 (void) _f->readUint16LE();
74 byte skipB, skipW;
75 skipB = _f->readByte();
76 skipW = _f->readByte();
78 assert(_s.pitch == 320);
80 int left = 320 * 200;
81 byte *dest = reinterpret_cast<byte *>(_s.pixels);
83 while (left) {
84 byte b = _f->readByte();
86 uint16 s;
87 if (b == skipB && (s = _f->readByte())) {
88 dest += s;
89 left -= s;
90 continue;
91 } else if (b == skipW && (s = _f->readUint16LE())) {
92 dest += s;
93 left -= s;
94 continue;
97 *dest++ = b;
98 left--;
101 _iFrames--;
104 void Movie::showFrame() {
105 Engine::instance()._system->copyRectToScreen(
106 reinterpret_cast<byte *>(_s.pixels), _s.pitch, 0, 0, _s.w, _s.h);
108 Engine::instance()._system->updateScreen();
111 void Movie::setPalette() {
112 Graf.setPalette(_pal, 0, 256);
115 void Movie::delay() {
116 Engine::instance().delay(40 * (1+_delay));
119 } // end of namespace Innocent