Ticket #9141: vid_dec_engines.diff
File vid_dec_engines.diff, 51.6 KB (added by , 14 years ago) |
---|
-
engines/mohawk/video/cinepak.h
65 65 ~CinepakDecoder(); 66 66 67 67 Graphics::Surface *decodeImage(Common::SeekableReadStream *stream); 68 Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; } 68 69 69 70 private: 70 71 CinepakFrame _curFrame; -
engines/mohawk/video/rpza.h
37 37 ~RPZADecoder() { delete _surface; } 38 38 39 39 Graphics::Surface *decodeImage(Common::SeekableReadStream *stream); 40 Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; } 40 41 41 42 private: 42 43 Graphics::Surface *_surface; -
engines/mohawk/video/smc.h
43 43 ~SMCDecoder() { delete _surface; } 44 44 45 45 Graphics::Surface *decodeImage(Common::SeekableReadStream *stream); 46 Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); } 46 47 47 48 private: 48 49 Graphics::Surface *_surface; -
engines/mohawk/video/qtrle.h
37 37 ~QTRLEDecoder(); 38 38 39 39 Graphics::Surface *decodeImage(Common::SeekableReadStream *stream); 40 Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; } 40 41 41 42 private: 42 43 byte _bitsPerPixel; -
engines/mohawk/jpeg.h
45 45 ~JPEGDecoder(); 46 46 47 47 Graphics::Surface *decodeImage(Common::SeekableReadStream *stream); 48 Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; } 48 49 49 50 private: 50 51 Graphics::PixelFormat _pixelFormat; -
engines/tucker/sequences.cpp
537 537 } 538 538 // budttle2.flc is shorter in french version ; start the background music 539 539 // earlier and skip any sounds effects 540 if (_seqNum == 19 && _flicPlayer[0].getFrameCount() == 12 6) {540 if (_seqNum == 19 && _flicPlayer[0].getFrameCount() == 127) { 541 541 _soundSeqDataIndex = 6; 542 _frameCounter = 80;542 _frameCounter = 79; 543 543 } 544 544 } 545 545 (this->*(_updateFunc[_updateFuncIndex].play))(); … … 766 766 } 767 767 768 768 bool AnimationSequencePlayer::decodeNextAnimationFrame(int index) { 769 bool framesLeft = _flicPlayer[index].decodeNextFrame(); 769 ::Graphics::Surface *surface = _flicPlayer[index].decodeNextFrame(); 770 770 771 if (_seqNum == 19) { 771 _flicPlayer[index].copyFrameToBuffer(_offscreenBuffer, 0, 0, kScreenWidth); 772 for (uint16 y = 0; (y < surface->h) && (y < kScreenHeight); y++) 773 memcpy(_offscreenBuffer + y * kScreenWidth, (byte *)surface->pixels + y * surface->pitch, surface->w); 772 774 } else { 773 775 _flicPlayer[index].copyDirtyRectsToBuffer(_offscreenBuffer, kScreenWidth); 774 776 } 777 775 778 ++_frameCounter; 776 if (index == 0) { 777 if (_flicPlayer[index].paletteChanged()) { 778 getRGBPalette(index); 779 } 780 } 781 return framesLeft; 779 780 if (index == 0 && _flicPlayer[index].hasDirtyPalette()) 781 getRGBPalette(index); 782 783 return !_flicPlayer[index].endOfVideo(); 782 784 } 783 785 784 786 void AnimationSequencePlayer::loadIntroSeq17_18() { … … 803 805 // The intro credits animation. This uses 2 animations: the foreground one, which 804 806 // is the actual intro credits, and the background one, which is an animation of 805 807 // cogs, and is being replayed when an intro credit appears 806 if (_flicPlayer[0].getCurFrame() >= 116) { 807 if (!_flicPlayer[1].decodeNextFrame()) { 808 ::Graphics::Surface *surface = 0; 809 810 if (_flicPlayer[0].getCurFrame() >= 117) { 811 surface = _flicPlayer[1].decodeNextFrame(); 812 if (_flicPlayer[1].endOfVideo()) 808 813 _flicPlayer[1].reset(); 809 }810 814 } 815 811 816 bool framesLeft = decodeNextAnimationFrame(0); 812 for (int i = 0; i < kScreenWidth * kScreenHeight; ++i) { 813 if (_offscreenBuffer[i] == 0) { 814 _offscreenBuffer[i] = _flicPlayer[1].getPixel(i); 815 } 816 } 817 if (!framesLeft) { 817 818 if (surface) 819 for (int i = 0; i < kScreenWidth * kScreenHeight; ++i) 820 if (_offscreenBuffer[i] == 0) 821 _offscreenBuffer[i] = *((byte *)surface->pixels + i); 822 823 if (!framesLeft) 818 824 _changeToNextSequence = true; 819 }820 825 } 821 826 822 827 void AnimationSequencePlayer::displayLoadingScreen() { … … 870 875 void AnimationSequencePlayer::playIntroSeq3_4() { 871 876 if (!_updateScreenPicture) { 872 877 bool framesLeft = decodeNextAnimationFrame(0); 873 if (_flicPlayer[0].getCurFrame() == 70 6) {878 if (_flicPlayer[0].getCurFrame() == 707) { 874 879 initPicPart4(); 875 880 } 876 881 if (!framesLeft) { … … 909 914 } 910 915 911 916 void AnimationSequencePlayer::drawPic1Part10() { 917 ::Graphics::Surface *surface = _flicPlayer[0].decodeNextFrame(); 918 _flicPlayer[0].copyDirtyRectsToBuffer(_offscreenBuffer, kScreenWidth); 919 ++_frameCounter; 920 921 if (_flicPlayer[0].hasDirtyPalette()) 922 getRGBPalette(0); 923 912 924 int offset = 0; 913 925 for (int y = 0; y < kScreenHeight; ++y) { 914 926 for (int x = 0; x < kScreenWidth; ++x) { 915 byte color = _flicPlayer[0].getPixel(offset); 916 if (color == 0) { 927 byte color = *((byte *)surface->pixels + offset); 928 929 if (color == 0) 917 930 color = _picBufPtr[800 + y * 640 + _updateScreenWidth + x]; 918 } 931 919 932 _offscreenBuffer[offset++] = color; 920 933 } 921 934 } … … 930 943 } 931 944 932 945 void AnimationSequencePlayer::playIntroSeq9_10() { 933 bool framesLeft = decodeNextAnimationFrame(0); 934 if (_flicPlayer[0].getCurFrame() >= 264 && _flicPlayer[0].getCurFrame() <= 295) { 946 if (_flicPlayer[0].getCurFrame() >= 265 && _flicPlayer[0].getCurFrame() <= 296) { 935 947 drawPic1Part10(); 936 948 _updateScreenWidth += 6; 937 } else if (_flicPlayer[0].getCurFrame() == 984) { 949 } else if (_flicPlayer[0].getCurFrame() == 985) { 950 decodeNextAnimationFrame(0); 938 951 drawPic2Part10(); 939 } else if (_flicPlayer[0].getCurFrame() >= 98 8 && _flicPlayer[0].getCurFrame() <= 996) {952 } else if (_flicPlayer[0].getCurFrame() >= 989 && _flicPlayer[0].getCurFrame() <= 997) { 940 953 drawPic1Part10(); 941 954 _updateScreenWidth -= 25; 942 955 if (_updateScreenWidth < 0) { 943 956 _updateScreenWidth = 0; 944 957 } 945 958 } 946 if (!framesLeft) { 959 960 if (_flicPlayer[0].endOfVideo()) 947 961 _changeToNextSequence = true; 948 }949 962 } 950 963 951 964 void AnimationSequencePlayer::loadIntroSeq21_22() { -
engines/saga/scene.h
424 424 int DinoStartProc(); 425 425 int FTA2StartProc(); 426 426 int FTA2EndProc(FTA2Endings whichEnding); 427 void playMovie(const char *filename); 427 428 428 429 void IHNMLoadCutaways(); 429 430 bool checkKey(); -
engines/saga/introproc_saga2.cpp
40 40 int Scene::DinoStartProc() { 41 41 _vm->_gfx->showCursor(false); 42 42 43 Graphics::SmackerDecoder *smkDecoder = new Graphics::SmackerDecoder(_vm->_mixer); 44 Graphics::VideoPlayer *player = new Graphics::VideoPlayer(smkDecoder); 45 if (smkDecoder->loadFile("testvid.smk")) 46 player->playVideo(); // Play introduction 47 smkDecoder->closeFile(); 48 delete player; 49 delete smkDecoder; 43 playMovie("testvid.smk"); 50 44 51 45 // HACK: Forcibly quit here 52 46 _vm->quitGame(); … … 57 51 int Scene::FTA2StartProc() { 58 52 _vm->_gfx->showCursor(false); 59 53 60 Graphics::SmackerDecoder *smkDecoder = new Graphics::SmackerDecoder(_vm->_mixer); 61 Graphics::VideoPlayer *player = new Graphics::VideoPlayer(smkDecoder); 62 if (smkDecoder->loadFile("trimark.smk")) 63 player->playVideo(); // Show Ignite logo 64 smkDecoder->closeFile(); 65 if (smkDecoder->loadFile("intro.smk")) 66 player->playVideo(); // Play introduction 67 smkDecoder->closeFile(); 68 delete player; 69 delete smkDecoder; 54 playMovie("trimark.smk"); 55 playMovie("intro.smk"); 70 56 71 57 // HACK: Forcibly quit here 72 58 _vm->quitGame(); … … 100 86 _vm->_gfx->showCursor(false); 101 87 102 88 // Play ending 103 Graphics::SmackerDecoder *smkDecoder = new Graphics::SmackerDecoder(_vm->_mixer); 104 Graphics::VideoPlayer *player = new Graphics::VideoPlayer(smkDecoder); 105 if (smkDecoder->loadFile(videoName)) { 106 player->playVideo(); 107 smkDecoder->closeFile(); 108 } 109 delete player; 110 delete smkDecoder; 89 playMovie(videoName); 111 90 112 91 return SUCCESS; 113 92 } 114 93 94 void Scene::playMovie(const char *filename) { 95 Graphics::SmackerDecoder *smkDecoder = new Graphics::SmackerDecoder(_vm->_mixer); 96 97 if (!smkDecoder->loadFile(filename)) 98 return; 99 100 uint16 x = (g_system->getWidth() - smkDecoder->getWidth()) / 2; 101 uint16 y = (g_system->getHeight() - smkDecoder->getHeight()) / 2; 102 103 while (!_vm->shouldQuit() && !smkDecoder->endOfVideo()) { 104 if (smkDecoder->needsUpdate()) { 105 Graphics::Surface *frame = smkDecoder->decodeNextFrame(); 106 if (frame) { 107 _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); 108 109 if (smkDecoder->hasDirtyPalette()) 110 smkDecoder->setSystemPalette(); 111 112 _vm->_system->updateScreen(); 113 } 114 } 115 116 Common::Event event; 117 while (_vm->_system->getEventManager()->pollEvent(event)) 118 ; 119 120 _vm->_system->delayMillis(10); 121 } 122 } 123 115 124 } // End of namespace Saga 116 125 117 126 #endif -
engines/sci/console.cpp
222 222 if (!_videoFile.empty()) { 223 223 _engine->_gfxCursor->kernelHide(); 224 224 225 Graphics::VideoDecoder *videoDecoder = 0; 226 225 227 if (_videoFile.hasSuffix(".seq")) { 226 SeqDecoder *seqDecoder = new SeqDecoder(); 227 Graphics::VideoPlayer *player = new Graphics::VideoPlayer(seqDecoder); 228 if (seqDecoder->loadFile(_videoFile.c_str(), _videoFrameDelay)) 229 player->playVideo(); 230 else 231 DebugPrintf("Failed to open movie file %s\n", _videoFile.c_str()); 232 seqDecoder->closeFile(); 233 delete player; 234 delete seqDecoder; 235 } else if (_videoFile.hasSuffix(".avi")) { 236 Graphics::AviDecoder *aviDecoder = new Graphics::AviDecoder(g_system->getMixer()); 237 Graphics::VideoPlayer *player = new Graphics::VideoPlayer(aviDecoder); 238 if (aviDecoder->loadFile(_videoFile.c_str())) 239 player->playVideo(); 240 else 241 DebugPrintf("Failed to open movie file %s\n", _videoFile.c_str()); 242 aviDecoder->closeFile(); 243 delete player; 244 delete aviDecoder; 228 videoDecoder = new SeqDecoder(); 229 ((SeqDecoder *)videoDecoder)->setFrameDelay(_videoFrameDelay); 230 #ifdef ENABLE_SCI32 245 231 } else if (_videoFile.hasSuffix(".vmd")) { 246 #ifdef ENABLE_SCI32 247 VMDDecoder *vmdDecoder = new VMDDecoder(g_system->getMixer()); 248 Graphics::VideoPlayer *player = new Graphics::VideoPlayer(vmdDecoder); 249 if (vmdDecoder->loadFile(_videoFile.c_str())) 250 player->playVideo(); 251 else 252 DebugPrintf("Failed to open movie file %s\n", _videoFile.c_str()); 253 vmdDecoder->closeFile(); 254 delete player; 255 delete vmdDecoder; 232 videoDecoder = new VMDDecoder(g_system->getMixer()); 256 233 #endif 234 } else if (_videoFile.hasSuffix(".avi")) { 235 videoDecoder = new Graphics::AviDecoder(g_system->getMixer()); 257 236 } 258 237 238 if (videoDecoder && videoDecoder->loadFile(_videoFile)) { 239 uint16 x = (g_system->getWidth() - videoDecoder->getWidth()) / 2; 240 uint16 y = (g_system->getHeight() - videoDecoder->getHeight()) / 2; 241 242 while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo()) { 243 if (videoDecoder->needsUpdate()) { 244 Graphics::Surface *frame = videoDecoder->decodeNextFrame(); 245 if (frame) { 246 g_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); 247 248 if (videoDecoder->hasDirtyPalette()) 249 videoDecoder->setSystemPalette(); 250 251 g_system->updateScreen(); 252 } 253 } 254 255 Common::Event event; 256 while (g_system->getEventManager()->pollEvent(event)) 257 ; 258 259 g_system->delayMillis(10); 260 } 261 262 delete videoDecoder; 263 } else 264 warning("Could not play video %s\n", _videoFile.c_str()); 265 259 266 _engine->_gfxCursor->kernelShow(); 260 261 267 _videoFile.clear(); 262 268 _videoFrameDelay = 0; 263 269 } -
engines/sci/engine/kgraphics.cpp
1075 1075 } 1076 1076 1077 1077 reg_t kShowMovie(EngineState *s, int argc, reg_t *argv) { 1078 bool playedVideo = false;1079 1080 1078 // Hide the cursor if it's showing and then show it again if it was 1081 1079 // previously visible. 1082 1080 bool reshowCursor; … … 1084 1082 reshowCursor = g_sci->_gfxCursor->isVisible(); 1085 1083 if (reshowCursor) 1086 1084 g_sci->_gfxCursor->kernelHide(); 1085 1086 Graphics::VideoDecoder *videoDecoder = 0; 1087 1087 1088 1088 if (argv[0].segment != 0) { 1089 1089 // DOS SEQ 1090 1090 // SEQ's are called with no subops, just the string and delay 1091 1091 Common::String filename = s->_segMan->getString(argv[0]); 1092 int delay = argv[1].toUint16(); // Time between frames in ticks1093 1092 1094 1093 SeqDecoder *seqDecoder = new SeqDecoder(); 1095 Graphics::VideoPlayer *player = new Graphics::VideoPlayer(seqDecoder); 1096 if (seqDecoder->loadFile(filename.c_str(), delay)) { 1097 player->playVideo(); 1098 playedVideo = true; 1099 } else { 1094 seqDecoder->setFrameDelay(argv[1].toUint16()); 1095 videoDecoder = seqDecoder; 1096 1097 if (!videoDecoder->loadFile(filename)) { 1100 1098 warning("Failed to open movie file %s", filename.c_str()); 1099 delete videoDecoder; 1100 videoDecoder = 0; 1101 1101 } 1102 seqDecoder->closeFile();1103 delete player;1104 delete seqDecoder;1105 1102 } else { 1106 1103 // Windows AVI (Macintosh QuickTime? Need to check KQ6 Macintosh) 1107 1104 // TODO: This appears to be some sort of subop. case 0 contains the string … … 1120 1117 switch (argv[0].toUint16()) { 1121 1118 case 0: { 1122 1119 Common::String filename = s->_segMan->getString(argv[1]); 1123 Graphics::AviDecoder *aviDecoder = new Graphics::AviDecoder(g_system->getMixer()); 1124 Graphics::VideoPlayer *player = new Graphics::VideoPlayer(aviDecoder); 1125 if (aviDecoder->loadFile(filename.c_str())) { 1126 player->playVideo(); 1127 playedVideo = true; 1128 } else { 1120 videoDecoder = new Graphics::AviDecoder(g_system->getMixer()); 1121 1122 if (!videoDecoder->loadFile(filename.c_str())) { 1129 1123 warning("Failed to open movie file %s", filename.c_str()); 1124 delete videoDecoder; 1125 videoDecoder = 0; 1130 1126 } 1131 aviDecoder->closeFile();1132 delete player;1133 delete aviDecoder;1134 1127 break; 1135 1128 } 1136 1129 default: … … 1138 1131 } 1139 1132 } 1140 1133 1141 if (playedVideo) 1134 if (videoDecoder) { 1135 uint16 x = (g_system->getWidth() - videoDecoder->getWidth()) / 2; 1136 uint16 y = (g_system->getHeight() - videoDecoder->getHeight()) / 2; 1137 1138 while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo()) { 1139 if (videoDecoder->needsUpdate()) { 1140 Graphics::Surface *frame = videoDecoder->decodeNextFrame(); 1141 if (frame) { 1142 g_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); 1143 1144 if (videoDecoder->hasDirtyPalette()) 1145 videoDecoder->setSystemPalette(); 1146 1147 g_system->updateScreen(); 1148 } 1149 } 1150 1151 Common::Event event; 1152 while (g_system->getEventManager()->pollEvent(event)) 1153 ; 1154 1155 g_system->delayMillis(10); 1156 } 1157 1158 delete videoDecoder; 1142 1159 g_sci->_gfxScreen->kernelSyncWithFramebuffer(); 1160 } 1143 1161 1144 1162 if (reshowCursor) 1145 1163 g_sci->_gfxCursor->kernelShow(); -
engines/sci/video/vmd_decoder.h
29 29 #define GRAPHICS_VIDEO_VMD_DECODER_H 30 30 31 31 #include "graphics/video/coktelvideo/coktelvideo.h" 32 #include "graphics/video/video_ player.h"32 #include "graphics/video/video_decoder.h" 33 33 #include "sound/mixer.h" 34 34 35 35 namespace Sci { … … 49 49 * - Shivers 2: Harvest of Souls 50 50 * - Torin's Passage 51 51 */ 52 class VMDDecoder : public Graphics:: VideoDecoder {52 class VMDDecoder : public Graphics::FixedRateVideoDecoder { 53 53 public: 54 54 VMDDecoder(Audio::Mixer *mixer); 55 55 virtual ~VMDDecoder(); 56 56 57 57 uint32 getFrameWaitTime(); 58 58 59 /** 60 * Load a VMD encoded video file 61 * @param filename the filename to load 62 */ 63 bool loadFile(const char *filename); 59 bool load(Common::SeekableReadStream &stream); 60 void close(); 64 61 65 /** 66 * Close a VMD encoded video file 67 */ 68 void closeFile(); 62 bool isVideoLoaded() const { return _fileStream != 0; } 63 uint16 getWidth() const { return _surface->w; } 64 uint16 getHeight() const { return _surface->h; } 65 uint32 getFrameCount() const { return _vmdDecoder->getFramesCount(); } 66 Graphics::Surface *decodeNextFrame(); 67 Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); } 68 byte *getPalette() { _dirtyPalette = false; return _palette; } 69 bool hasDirtyPalette() const { return _dirtyPalette; } 69 70 70 bool decodeNextFrame(); 71 protected: 72 Common::Rational getFrameRate() const { return _vmdDecoder->getFrameRate(); } 71 73 72 74 private: 73 75 Graphics::Vmd *_vmdDecoder; 74 76 Audio::Mixer *_mixer; 77 Graphics::Surface *_surface; 78 Common::SeekableReadStream *_fileStream; 75 79 byte _palette[256 * 3]; 80 bool _dirtyPalette; 76 81 77 void getPalette();82 void loadPaletteFromVMD(); 78 83 }; 79 84 80 85 } // End of namespace Graphics -
engines/sci/video/seq_decoder.h
26 26 #ifndef SEQ_DECODER_H 27 27 #define SEQ_DECODER_H 28 28 29 #include "graphics/video/video_ player.h"29 #include "graphics/video/video_decoder.h" 30 30 31 31 namespace Sci { 32 32 33 33 /** 34 34 * Implementation of the Sierra SEQ decoder, used in KQ6 DOS floppy/CD and GK1 DOS 35 35 */ 36 class SeqDecoder : public Graphics:: VideoDecoder {36 class SeqDecoder : public Graphics::FixedRateVideoDecoder { 37 37 public: 38 SeqDecoder() {}38 SeqDecoder(); 39 39 virtual ~SeqDecoder(); 40 40 41 /** 42 * Load a SEQ encoded video file 43 * @param filename the filename to load 44 */ 45 bool loadFile(const char *fileName) { return loadFile(fileName, 10); } 41 bool load(Common::SeekableReadStream &stream); 42 void close(); 46 43 47 /** 48 * Load a SEQ encoded video file 49 * @param filename the filename to load 50 * @param frameDelay the delay between frames, in ticks 51 */ 52 bool loadFile(const char *fileName, int frameDelay); 44 void setFrameDelay(int frameDelay) { _frameDelay = frameDelay; } 53 45 54 /** 55 * Close a SEQ encoded video file 56 */ 57 void closeFile(); 46 bool isVideoLoaded() const { return _fileStream != 0; } 47 uint16 getWidth() const { return 320; } 48 uint16 getHeight() const { return 200; } 49 uint32 getFrameCount() const { return _frameCount; } 50 Graphics::Surface *decodeNextFrame(); 51 Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat::createFormatCLUT8(); } 52 byte *getPalette() { _dirtyPalette = false; return _palette; } 53 bool hasDirtyPalette() const { return _dirtyPalette; } 54 55 protected: 56 Common::Rational getFrameRate() const { assert(_frameDelay); return Common::Rational(60, _frameDelay); } 58 57 59 bool decodeNextFrame();60 61 58 private: 62 59 bool decodeFrame(byte *rleData, int rleSize, byte *litData, int litSize, byte *dest, int left, int width, int height, int colorKey); 60 61 uint16 _width, _height; 62 uint16 _frameDelay; 63 Common::SeekableReadStream *_fileStream; 64 byte _palette[256 * 3]; 65 bool _dirtyPalette; 66 uint32 _frameCount; 67 Graphics::Surface *_surface; 63 68 }; 64 69 65 70 } // End of namespace Sci -
engines/sci/video/vmd_decoder.cpp
27 27 28 28 #include "sci/video/vmd_decoder.h" 29 29 30 #include "common/archive.h"31 30 #include "common/endian.h" 32 31 #include "common/util.h" 33 32 #include "common/stream.h" … … 42 41 43 42 VMDDecoder::VMDDecoder(Audio::Mixer *mixer) : _mixer(mixer) { 44 43 _vmdDecoder = new Graphics::Vmd(new Graphics::PaletteLUT(5, Graphics::PaletteLUT::kPaletteYUV)); 44 _surface = 0; 45 _dirtyPalette = false; 46 _fileStream = 0; 45 47 } 46 48 47 49 VMDDecoder::~VMDDecoder() { 48 close File();50 close(); 49 51 } 50 52 51 uint32 VMDDecoder::getFrameWaitTime() { 52 return _vmdDecoder->getFrameWaitTime(); 53 } 53 bool VMDDecoder::load(Common::SeekableReadStream &stream) { 54 close(); 54 55 55 bool VMDDecoder::loadFile(const char *fileName) { 56 closeFile(); 57 58 _fileStream = SearchMan.createReadStreamForMember(fileName); 59 if (!_fileStream) 56 if (!_vmdDecoder->load(stream)) 60 57 return false; 61 58 62 if (!_vmdDecoder->load(*_fileStream)) 63 return false; 59 _fileStream = &stream; 64 60 65 if (_vmdDecoder->getFeatures() & Graphics::CoktelVideo::kFeaturesPalette) { 66 getPalette(); 67 setPalette(_palette); 68 } 61 if (_vmdDecoder->getFeatures() & Graphics::CoktelVideo::kFeaturesPalette) 62 loadPaletteFromVMD(); 69 63 70 64 if (_vmdDecoder->getFeatures() & Graphics::CoktelVideo::kFeaturesSound) 71 65 _vmdDecoder->enableSound(*_mixer); 72 66 73 _videoInfo.width = _vmdDecoder->getWidth();74 _videoInfo.height = _vmdDecoder->getHeight();75 _videoInfo.frameCount = _vmdDecoder->getFramesCount();76 _videoInfo.frameRate = _vmdDecoder->getFrameRate();77 _videoInfo.frameDelay = _videoInfo.frameRate * 100;78 _videoInfo.currentFrame = -1;79 _videoInfo.firstframeOffset = 0; // not really necessary for VMDs80 81 67 if (_vmdDecoder->hasExtraData()) 82 68 warning("This VMD video has extra embedded data, which is currently not handled"); 83 69 84 _videoFrameBuffer = new byte[_videoInfo.width * _videoInfo.height]; 85 memset(_videoFrameBuffer, 0, _videoInfo.width * _videoInfo.height); 86 87 _vmdDecoder->setVideoMemory(_videoFrameBuffer, _videoInfo.width, _videoInfo.height); 88 70 _surface = new Graphics::Surface(); 71 _surface->create(_vmdDecoder->getWidth(), _vmdDecoder->getHeight(), 1); 72 _vmdDecoder->setVideoMemory((byte *)_surface->pixels, _surface->w, _surface->h); 89 73 return true; 90 74 } 91 75 92 void VMDDecoder::close File() {76 void VMDDecoder::close() { 93 77 if (!_fileStream) 94 78 return; 95 79 … … 98 82 delete _fileStream; 99 83 _fileStream = 0; 100 84 101 delete[] _videoFrameBuffer; 102 _videoFrameBuffer = 0; 85 _surface->free(); 86 delete _surface; 87 _surface = 0; 88 89 reset(); 103 90 } 104 91 105 bool VMDDecoder::decodeNextFrame() { 106 _videoInfo.currentFrame++; 107 108 if (_videoInfo.currentFrame == 0) 109 _videoInfo.startTime = g_system->getMillis(); 110 92 Graphics::Surface *VMDDecoder::decodeNextFrame() { 111 93 Graphics::CoktelVideo::State state = _vmdDecoder->nextFrame(); 112 94 113 if (state.flags & Graphics::CoktelVideo::kStatePalette) { 114 getPalette(); 115 setPalette(_palette); 116 } 95 if (state.flags & Graphics::CoktelVideo::kStatePalette) 96 loadPaletteFromVMD(); 117 97 118 return !endOfVideo(); 98 if (_curFrame == -1) 99 _startTime = g_system->getMillis(); 100 101 _curFrame++; 102 return _surface; 119 103 } 120 104 121 void VMDDecoder:: getPalette() {105 void VMDDecoder::loadPaletteFromVMD() { 122 106 const byte *pal = _vmdDecoder->getPalette(); 123 107 124 108 for (int i = 0; i < 256; i++) { … … 126 110 _palette[i * 3 + 1] = pal[i * 3 + 1] << 2; 127 111 _palette[i * 3 + 2] = pal[i * 3 + 2] << 2; 128 112 } 113 114 _dirtyPalette = true; 129 115 } 130 116 131 117 } // End of namespace Graphics -
engines/sci/video/seq_decoder.cpp
35 35 36 36 namespace Sci { 37 37 38 // SEQ videos always run at 320x20039 #define SCREEN_WIDTH 32040 #define SCREEN_HEIGHT 20041 42 38 enum seqPalTypes { 43 39 kSeqPalVariable = 0, 44 40 kSeqPalConstant = 1 … … 49 45 kSeqFrameDiff = 1 50 46 }; 51 47 48 SeqDecoder::SeqDecoder() { 49 _fileStream = 0; 50 _surface = 0; 51 _dirtyPalette = false; 52 } 53 52 54 SeqDecoder::~SeqDecoder() { 53 close File();55 close(); 54 56 } 55 57 56 bool SeqDecoder::load File(const char *fileName, int frameDelay) {57 close File();58 bool SeqDecoder::load(Common::SeekableReadStream &stream) { 59 close(); 58 60 59 _fileStream = SearchMan.createReadStreamForMember(fileName);60 if (!_fileStream)61 return false;61 _fileStream = &stream; 62 _surface = new Graphics::Surface(); 63 _surface->create(getWidth(), getHeight(), 1); 62 64 63 // Seek to the first frame 64 _videoInfo.currentFrame = -1; 65 _frameCount = _fileStream->readUint16LE(); 65 66 66 _videoInfo.width = SCREEN_WIDTH;67 _videoInfo.height = SCREEN_HEIGHT;68 _videoInfo.frameCount = _fileStream->readUint16LE();69 // Our frameDelay is calculated in 1/100 ms, so we convert it here70 _videoInfo.frameDelay = 100 * frameDelay * 1000 / 60;71 _videoFrameBuffer = new byte[_videoInfo.width * _videoInfo.height];72 73 67 // Set palette 74 68 int paletteSize = _fileStream->readUint32LE(); 75 69 … … 81 75 uint16 palColorStart = READ_LE_UINT16(paletteData + 25); 82 76 uint16 palColorCount = READ_LE_UINT16(paletteData + 29); 83 77 84 byte palette[256 * 4];85 78 int palOffset = 37; 86 79 87 80 for (uint16 colorNo = palColorStart; colorNo < palColorStart + palColorCount; colorNo++) { 88 81 if (palFormat == kSeqPalVariable) 89 82 palOffset++; 90 palette[colorNo * 4 + 0] = paletteData[palOffset++]; 91 palette[colorNo * 4 + 1] = paletteData[palOffset++]; 92 palette[colorNo * 4 + 2] = paletteData[palOffset++]; 93 palette[colorNo * 4 + 3] = 0; 83 _palette[colorNo * 3 + 0] = paletteData[palOffset++]; 84 _palette[colorNo * 3 + 1] = paletteData[palOffset++]; 85 _palette[colorNo * 3 + 2] = paletteData[palOffset++]; 94 86 } 95 87 96 g_system->setPalette(palette, 0, 256); 97 88 _dirtyPalette = true; 98 89 delete[] paletteData; 99 100 _videoInfo.firstframeOffset = _fileStream->pos();101 102 90 return true; 103 91 } 104 92 105 void SeqDecoder::close File() {93 void SeqDecoder::close() { 106 94 if (!_fileStream) 107 95 return; 108 96 97 _frameDelay = 0; 98 109 99 delete _fileStream; 110 100 _fileStream = 0; 111 101 112 delete[] _videoFrameBuffer; 113 _videoFrameBuffer = 0; 102 _surface->free(); 103 delete _surface; 104 _surface = 0; 105 106 reset(); 114 107 } 115 108 116 boolSeqDecoder::decodeNextFrame() {109 Graphics::Surface *SeqDecoder::decodeNextFrame() { 117 110 int16 frameWidth = _fileStream->readUint16LE(); 118 111 int16 frameHeight = _fileStream->readUint16LE(); 119 112 int16 frameLeft = _fileStream->readUint16LE(); … … 129 122 130 123 _fileStream->seek(offset); 131 124 132 _videoInfo.currentFrame++;133 134 if (_videoInfo.currentFrame == 0)135 _videoInfo.startTime = g_system->getMillis();136 137 125 if (frameType == kSeqFrameFull) { 138 byte *dst = _videoFrameBuffer + frameTop * SCREEN_WIDTH+ frameLeft;126 byte *dst = (byte *)_surface->pixels + frameTop * getWidth() + frameLeft; 139 127 140 128 byte *linebuf = new byte[frameWidth]; 141 129 142 130 do { 143 131 _fileStream->read(linebuf, frameWidth); 144 132 memcpy(dst, linebuf, frameWidth); 145 dst += SCREEN_WIDTH;133 dst += getWidth(); 146 134 } while (--frameHeight); 147 135 148 136 delete[] linebuf; 149 137 } else { 150 138 byte *buf = new byte[frameSize]; 151 139 _fileStream->read(buf, frameSize); 152 decodeFrame(buf, rleSize, buf + rleSize, frameSize - rleSize, _videoFrameBuffer + SCREEN_WIDTH* frameTop, frameLeft, frameWidth, frameHeight, colorKey);140 decodeFrame(buf, rleSize, buf + rleSize, frameSize - rleSize, (byte *)_surface->pixels + getWidth() * frameTop, frameLeft, frameWidth, frameHeight, colorKey); 153 141 delete[] buf; 154 142 } 155 143 156 return !endOfVideo(); 144 if (_curFrame == -1) 145 _startTime = g_system->getMillis(); 146 147 _curFrame++; 148 return _surface; 157 149 } 158 150 159 151 #define WRITE_TO_BUFFER(n) \ 160 if (writeRow * SCREEN_WIDTH + writeCol + (n) > SCREEN_WIDTH* height) { \152 if (writeRow * getWidth() + writeCol + (n) > getWidth() * height) { \ 161 153 warning("SEQ player: writing out of bounds, aborting"); \ 162 154 return false; \ 163 155 } \ 164 156 if (litPos + (n) > litSize) { \ 165 157 warning("SEQ player: reading out of bounds, aborting"); \ 166 158 } \ 167 memcpy(dest + writeRow * SCREEN_WIDTH+ writeCol, litData + litPos, n);159 memcpy(dest + writeRow * getWidth() + writeCol, litData + litPos, n); 168 160 169 161 bool SeqDecoder::decodeFrame(byte *rleData, int rleSize, byte *litData, int litSize, byte *dest, int left, int width, int height, int colorKey) { 170 162 int writeRow = 0; -
engines/sword1/animation.h
28 28 29 29 #include "graphics/video/dxa_decoder.h" 30 30 #include "graphics/video/smk_decoder.h" 31 #include "graphics/video/video_ player.h"31 #include "graphics/video/video_decoder.h" 32 32 33 33 #include "common/array.h" 34 34 … … 64 64 DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle); 65 65 ~DXADecoderWithSound() {} 66 66 67 int32 getAudioLag(); 67 uint32 getElapsedTime() const; 68 68 69 private: 69 70 Audio::Mixer *_mixer; 70 71 Audio::SoundHandle *_bgSoundHandle; 71 72 }; 72 73 73 class MoviePlayer : public Graphics::VideoPlayer{74 class MoviePlayer { 74 75 public: 75 76 MoviePlayer(SwordEngine *vm, Text *textMan, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType); 76 77 virtual ~MoviePlayer(); 77 78 bool load(uint32 id); 78 79 void play(); 80 79 81 protected: 80 82 SwordEngine *_vm; 81 83 Text *_textMan; … … 85 87 int _textX, _textY, _textWidth, _textHeight; 86 88 DecoderType _decoderType; 87 89 90 Graphics::VideoDecoder *_decoder; 88 91 Audio::SoundHandle *_bgSoundHandle; 89 92 Audio::AudioStream *_bgSoundStream; 90 93 94 bool playVideo(); 91 95 void performPostProcessing(byte *screen); 96 97 byte findBlackPalIndex(); 98 byte findWhitePalIndex(); 92 99 }; 93 100 94 101 MoviePlayer *makeMoviePlayer(uint32 id, SwordEngine *vm, Text *textMan, Audio::Mixer *snd, OSystem *system); -
engines/sword1/animation.cpp
68 68 /////////////////////////////////////////////////////////////////////////////// 69 69 70 70 MoviePlayer::MoviePlayer(SwordEngine *vm, Text *textMan, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType) 71 : _vm(vm), _textMan(textMan), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system) , VideoPlayer(decoder){71 : _vm(vm), _textMan(textMan), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system) { 72 72 _bgSoundStream = NULL; 73 73 _decoderType = decoderType; 74 _decoder = decoder; 74 75 } 75 76 76 77 MoviePlayer::~MoviePlayer() { … … 86 87 Common::File f; 87 88 char filename[20]; 88 89 89 if (_decoderType == kVideoDecoderDXA) {90 if (_decoderType == kVideoDecoderDXA) 90 91 _bgSoundStream = Audio::SeekableAudioStream::openStreamFile(sequenceList[id]); 91 } else {92 else 92 93 _bgSoundStream = NULL; 93 }94 94 95 95 if (SwordEngine::_systemVars.showText) { 96 96 sprintf(filename, "%s.txt", sequenceList[id]); … … 146 146 } 147 147 148 148 void MoviePlayer::play() { 149 if (_bgSoundStream) {149 if (_bgSoundStream) 150 150 _snd->playStream(Audio::Mixer::kSFXSoundType, _bgSoundHandle, _bgSoundStream); 151 } 151 152 152 bool terminated = false; 153 153 154 154 _textX = 0; … … 179 179 180 180 void MoviePlayer::performPostProcessing(byte *screen) { 181 181 if (!_movieTexts.empty()) { 182 if (_decoder->getCurFrame() + 1== _movieTexts[0]->_startFrame) {182 if (_decoder->getCurFrame() == _movieTexts[0]->_startFrame) { 183 183 _textMan->makeTextSprite(2, (uint8 *)_movieTexts[0]->_text, 600, LETTER_COL); 184 184 185 185 FrameHeader *frame = _textMan->giveSpriteData(2); … … 188 188 _textX = 320 - _textWidth / 2; 189 189 _textY = 420 - _textHeight; 190 190 } 191 if (_decoder->getCurFrame() + 1== _movieTexts[0]->_endFrame) {191 if (_decoder->getCurFrame() == _movieTexts[0]->_endFrame) { 192 192 _textMan->releaseText(2, false); 193 193 delete _movieTexts.remove_at(0); 194 194 } … … 205 205 for (x = 0; x < _textWidth; x++) { 206 206 switch (src[x]) { 207 207 case BORDER_COL: 208 dst[x] = _decoder->getBlack();208 dst[x] = findBlackPalIndex(); 209 209 break; 210 210 case LETTER_COL: 211 dst[x] = _decoder->getWhite();211 dst[x] = findWhitePalIndex(); 212 212 break; 213 213 } 214 214 } … … 228 228 229 229 for (y = 0; y < _textHeight; y++) { 230 230 if (_textY + y < frameY || _textY + y >= frameY + frameHeight) { 231 memset(dst + _textX, _decoder->getBlack(), _textWidth);231 memset(dst + _textX, findBlackPalIndex(), _textWidth); 232 232 } else { 233 233 if (frameX > _textX) 234 memset(dst + _textX, _decoder->getBlack(), frameX - _textX);234 memset(dst + _textX, findBlackPalIndex(), frameX - _textX); 235 235 if (frameX + frameWidth < _textX + _textWidth) 236 memset(dst + frameX + frameWidth, _decoder->getBlack(), _textX + _textWidth - (frameX + frameWidth));236 memset(dst + frameX + frameWidth, findBlackPalIndex(), _textX + _textWidth - (frameX + frameWidth)); 237 237 } 238 238 239 239 dst += _system->getWidth(); … … 244 244 } 245 245 } 246 246 247 DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle) 248 : _mixer(mixer), _bgSoundHandle(bgSoundHandle) { 247 bool MoviePlayer::playVideo() { 248 uint16 x = (g_system->getWidth() - _decoder->getWidth()) / 2; 249 uint16 y = (g_system->getHeight() - _decoder->getHeight()) / 2; 250 251 while (!_vm->shouldQuit() && !_decoder->endOfVideo()) { 252 if (_decoder->needsUpdate()) { 253 Graphics::Surface *frame = _decoder->decodeNextFrame(); 254 if (frame) 255 _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); 256 257 if (_decoder->hasDirtyPalette()) 258 _decoder->setSystemPalette(); 259 260 Graphics::Surface *screen = _vm->_system->lockScreen(); 261 performPostProcessing((byte *)screen->pixels); 262 _vm->_system->unlockScreen(); 263 _vm->_system->updateScreen(); 264 } 265 266 Common::Event event; 267 while (_vm->_system->getEventManager()->pollEvent(event)) 268 if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) 269 return false; 270 } 271 272 return !_vm->shouldQuit(); 249 273 } 250 274 251 int32 DXADecoderWithSound::getAudioLag() {252 if (!_fileStream)253 return 0; 275 byte MoviePlayer::findBlackPalIndex() { 276 return 0; 277 } 254 278 255 if (!_mixer->isSoundHandleActive(*_bgSoundHandle)) 256 return 0; 279 byte MoviePlayer::findWhitePalIndex() { 280 return 0xff; 281 } 257 282 258 int32 frameDelay = getFrameDelay(); 259 int32 videoTime = (_videoInfo.currentFrame + 1) * frameDelay;260 int32 audioTime; 283 DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle) 284 : _mixer(mixer), _bgSoundHandle(bgSoundHandle) { 285 } 261 286 262 const Audio::Timestamp ts = _mixer->getElapsedTime(*_bgSoundHandle); 263 audioTime = ts.convertToFramerate(100000).totalNumberOfFrames(); 287 uint32 DXADecoderWithSound::getElapsedTime() const { 288 if (_mixer->isSoundHandleActive(*_bgSoundHandle)) 289 return _mixer->getSoundElapsedTime(*_bgSoundHandle); 264 290 265 return videoTime - audioTime;291 return VideoDecoder::getElapsedTime(); 266 292 } 267 293 268 294 /////////////////////////////////////////////////////////////////////////////// -
engines/sword2/animation.h
30 30 31 31 #include "graphics/video/dxa_decoder.h" 32 32 #include "graphics/video/smk_decoder.h" 33 #include "graphics/video/video_ player.h"33 #include "graphics/video/video_decoder.h" 34 34 #include "sound/mixer.h" 35 35 36 36 #include "sword2/screen.h" … … 63 63 DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle); 64 64 ~DXADecoderWithSound() {} 65 65 66 int32 getAudioLag();66 uint32 getElapsedTime() const; 67 67 private: 68 68 Audio::Mixer *_mixer; 69 69 Audio::SoundHandle *_bgSoundHandle; 70 70 }; 71 71 72 class MoviePlayer : public Graphics::VideoPlayer{72 class MoviePlayer { 73 73 public: 74 74 MoviePlayer(Sword2Engine *vm, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType); 75 75 virtual ~MoviePlayer(); … … 89 89 int _textX, _textY; 90 90 DecoderType _decoderType; 91 91 92 Graphics::VideoDecoder *_decoder; 92 93 Audio::SoundHandle *_bgSoundHandle; 93 94 Audio::AudioStream *_bgSoundStream; 94 95 … … 96 97 int _leadOutFrame; 97 98 98 99 void performPostProcessing(byte *screen); 100 bool playVideo(); 99 101 100 102 void openTextObject(uint32 index); 101 103 void closeTextObject(uint32 index, byte *screen); 102 104 void drawTextObject(uint32 index, byte *screen); 105 106 byte findBlackPalIndex(); 107 byte findWhitePalIndex(); 103 108 }; 104 109 105 110 MoviePlayer *makeMoviePlayer(const char *name, Sword2Engine *vm, Audio::Mixer *snd, OSystem *system); -
engines/sword2/animation.cpp
47 47 /////////////////////////////////////////////////////////////////////////////// 48 48 49 49 MoviePlayer::MoviePlayer(Sword2Engine *vm, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType) 50 : _vm(vm), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system) , VideoPlayer(decoder){50 : _vm(vm), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system) { 51 51 _bgSoundStream = NULL; 52 52 _decoderType = decoderType; 53 _decoder = decoder; 53 54 } 54 55 55 56 MoviePlayer:: ~MoviePlayer() { … … 62 63 * @param id the id of the file 63 64 */ 64 65 bool MoviePlayer::load(const char *name) { 65 if (_decoderType == kVideoDecoderDXA) {66 if (_decoderType == kVideoDecoderDXA) 66 67 _bgSoundStream = Audio::SeekableAudioStream::openStreamFile(name); 67 } else {68 else 68 69 _bgSoundStream = NULL; 69 }70 70 71 71 _textSurface = NULL; 72 72 … … 97 97 _currentMovieText = 0; 98 98 _leadOut = leadOut; 99 99 100 if (leadIn) {100 if (leadIn) 101 101 _vm->_sound->playMovieSound(leadIn, kLeadInSound); 102 }103 102 104 if (_bgSoundStream) {103 if (_bgSoundStream) 105 104 _snd->playStream(Audio::Mixer::kSFXSoundType, _bgSoundHandle, _bgSoundStream); 106 }107 105 108 106 bool terminated = false; 109 107 … … 186 184 187 185 for (int y = 0; y < text->_textSprite.h; y++) { 188 186 if (_textY + y < frameY || _textY + y >= frameY + frameHeight) { 189 memset(dst + _textX, _decoder->getBlack(), text->_textSprite.w);187 memset(dst + _textX, findBlackPalIndex(), text->_textSprite.w); 190 188 } else { 191 189 if (frameX > _textX) 192 memset(dst + _textX, _decoder->getBlack(), frameX - _textX);190 memset(dst + _textX, findBlackPalIndex(), frameX - _textX); 193 191 if (frameX + frameWidth < _textX + text->_textSprite.w) 194 memset(dst + frameX + frameWidth, _decoder->getBlack(), _textX + text->_textSprite.w - (frameX + frameWidth));192 memset(dst + frameX + frameWidth, findBlackPalIndex(), _textX + text->_textSprite.w - (frameX + frameWidth)); 195 193 } 196 194 197 195 dst += _system->getWidth(); … … 207 205 void MoviePlayer::drawTextObject(uint32 index, byte *screen) { 208 206 MovieText *text = &_movieTexts[index]; 209 207 210 byte white = _decoder->getWhite();211 byte black = _decoder->getBlack();208 byte white = findWhitePalIndex(); 209 byte black = findBlackPalIndex(); 212 210 213 211 if (text->_textMem && _textSurface) { 214 212 byte *src = text->_textSprite.data; … … 240 238 241 239 void MoviePlayer::performPostProcessing(byte *screen) { 242 240 MovieText *text; 243 int frame = _decoder->getCurFrame() + 1;241 int frame = _decoder->getCurFrame(); 244 242 245 243 if (_currentMovieText < _numMovieTexts) { 246 244 text = &_movieTexts[_currentMovieText]; … … 272 270 } 273 271 } 274 272 275 DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle) 276 : _mixer(mixer), _bgSoundHandle(bgSoundHandle) { 273 bool MoviePlayer::playVideo() { 274 uint16 x = (g_system->getWidth() - _decoder->getWidth()) / 2; 275 uint16 y = (g_system->getHeight() - _decoder->getHeight()) / 2; 276 277 while (!_vm->shouldQuit() && !_decoder->endOfVideo()) { 278 if (_decoder->needsUpdate()) { 279 Graphics::Surface *frame = _decoder->decodeNextFrame(); 280 if (frame) 281 _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); 282 283 if (_decoder->hasDirtyPalette()) 284 _decoder->setSystemPalette(); 285 286 Graphics::Surface *screen = _vm->_system->lockScreen(); 287 performPostProcessing((byte *)screen->pixels); 288 _vm->_system->unlockScreen(); 289 _vm->_system->updateScreen(); 290 } 291 292 Common::Event event; 293 while (_vm->_system->getEventManager()->pollEvent(event)) 294 if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) 295 return false; 296 } 297 298 return !_vm->shouldQuit(); 277 299 } 278 300 279 int32 DXADecoderWithSound::getAudioLag() {280 if (!_fileStream)281 return 0; 301 byte MoviePlayer::findBlackPalIndex() { 302 return 0; 303 } 282 304 283 if (!_mixer->isSoundHandleActive(*_bgSoundHandle)) 284 return 0; 305 byte MoviePlayer::findWhitePalIndex() { 306 return 0xff; 307 } 285 308 286 int32 frameDelay = getFrameDelay(); 287 int32 videoTime = _videoInfo.currentFrame * frameDelay;288 int32 audioTime; 309 DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle) 310 : _mixer(mixer), _bgSoundHandle(bgSoundHandle) { 311 } 289 312 290 const Audio::Timestamp ts = _mixer->getElapsedTime(*_bgSoundHandle); 291 audioTime = ts.convertToFramerate(100000).totalNumberOfFrames(); 313 uint32 DXADecoderWithSound::getElapsedTime() const { 314 if (_mixer->isSoundHandleActive(*_bgSoundHandle)) 315 return _mixer->getSoundElapsedTime(*_bgSoundHandle); 292 316 293 return videoTime - audioTime;317 return VideoDecoder::getElapsedTime(); 294 318 } 295 319 296 320 /////////////////////////////////////////////////////////////////////////////// -
engines/scumm/he/animation_he.h
56 56 57 57 void copyFrameToBuffer(byte *dst, int dstType, uint x, uint y, uint pitch); 58 58 void handleNextFrame(); 59 60 protected:61 virtual void setPalette(byte *pal);62 59 }; 63 60 64 61 } // End of namespace Scumm -
engines/scumm/he/script_v90he.cpp
1437 1437 } 1438 1438 } else if (_videoParams.status == 165) { 1439 1439 // Stop video 1440 _moviePlay->close File();1440 _moviePlay->close(); 1441 1441 } 1442 1442 break; 1443 1443 default: -
engines/scumm/he/script_v100he.cpp
2254 2254 } 2255 2255 } else if (_videoParams.status == 19) { 2256 2256 // Stop video 2257 _moviePlay->close File();2257 _moviePlay->close(); 2258 2258 } 2259 2259 break; 2260 2260 default: -
engines/scumm/he/animation_he.cpp
46 46 } 47 47 48 48 int MoviePlayer::load(const char *filename, int flags, int image) { 49 if (isVideoLoaded()) { 50 closeFile(); 51 } 49 if (isVideoLoaded()) 50 close(); 52 51 53 if (!loadFile( filename)) {52 if (!loadFile(Common::String(filename))) { 54 53 warning("Failed to load video file %s", filename); 55 54 return -1; 56 55 } 56 57 57 debug(1, "Playing video %s", filename); 58 58 59 if (flags & 2) {59 if (flags & 2) 60 60 _vm->_wiz->createWizEmptyImage(image, 0, 0, getWidth(), getHeight()); 61 }62 61 63 62 _flags = flags; 64 63 _wizResNum = image; 65 66 64 return 0; 67 65 } 68 66 … … 70 68 uint h = getHeight(); 71 69 uint w = getWidth(); 72 70 73 byte *src = _videoFrameBuffer; 71 Graphics::Surface *surface = decodeNextFrame(); 72 byte *src = (byte *)surface->pixels; 74 73 74 if (hasDirtyPalette()) 75 _vm->setPaletteFromPtr(getPalette(), 256); 76 75 77 if (_vm->_game.features & GF_16BIT_COLOR) { 76 78 dst += y * pitch + x * 2; 77 79 do { … … 102 104 } 103 105 104 106 void MoviePlayer::handleNextFrame() { 105 if (!isVideoLoaded()) {107 if (!isVideoLoaded()) 106 108 return; 107 }108 109 109 110 VirtScreen *pvs = &_vm->_virtscr[kMainVirtScreen]; 110 111 111 decodeNextFrame();112 113 112 if (_flags & 2) { 114 113 uint8 *dstPtr = _vm->getResourceAddress(rtImage, _wizResNum); 115 114 assert(dstPtr); … … 129 128 } 130 129 131 130 if (endOfVideo()) 132 close File();131 close(); 133 132 } 134 133 135 void MoviePlayer::setPalette(byte *pal) {136 _vm->setPaletteFromPtr(pal, 256);137 }138 139 134 } // End of namespace Scumm 140 135 141 136 #endif // ENABLE_HE -
engines/agos/animation.h
72 72 virtual void handleNextFrame(); 73 73 virtual bool processFrame() = 0; 74 74 virtual void startSound() {} 75 76 protected: 77 uint32 _firstFrameOffset; 75 78 }; 76 79 77 80 class MoviePlayerDXA : public MoviePlayer, ::Graphics::DXADecoder { … … 84 87 void playVideo(); 85 88 void nextFrame(); 86 89 virtual void stopVideo(); 87 protected:88 void setPalette(byte *pal);89 90 90 91 private: 91 92 void handleNextFrame(); 92 93 bool processFrame(); 93 94 void startSound(); 95 void copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch); 94 96 }; 95 97 96 98 class MoviePlayerSMK : public MoviePlayer, ::Graphics::SmackerDecoder { … … 101 103 void playVideo(); 102 104 void nextFrame(); 103 105 virtual void stopVideo(); 104 protected: 105 void setPalette(byte *pal); 106 106 107 private: 107 108 void handleNextFrame(); 108 109 bool processFrame(); 109 110 void startSound(); 111 void copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch); 110 112 }; 111 113 112 114 MoviePlayer *makeMoviePlayer(AGOSEngine_Feeble *vm, const char *name); -
engines/agos/animation.cpp
241 241 } 242 242 243 243 bool MoviePlayerDXA::load() { 244 char videoName[20];245 uint i;246 247 244 if ((_vm->getPlatform() == Common::kPlatformAmiga || _vm->getPlatform() == Common::kPlatformMacintosh) && 248 245 _vm->_language != Common::EN_ANY) { 249 246 _sequenceNum = 0; 250 for ( i = 0; i < 90; i++) {247 for (uint i = 0; i < 90; i++) { 251 248 if (!scumm_stricmp(baseName, _sequenceList[i])) 252 249 _sequenceNum = i; 253 250 } 254 251 } 255 252 256 sprintf(videoName,"%s.dxa", baseName);253 Common::String videoName = Common::String::printf("%s.dxa", baseName); 257 254 if (!loadFile(videoName)) 258 error("Failed to load video file %s", videoName );255 error("Failed to load video file %s", videoName.c_str()); 259 256 260 debug(0, "Playing video %s", videoName );257 debug(0, "Playing video %s", videoName.c_str()); 261 258 262 259 CursorMan.showMouse(false); 263 260 261 _firstFrameOffset = _fileStream->pos(); 262 264 263 return true; 265 264 } 266 265 266 void MoviePlayerDXA::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) { 267 uint h = getHeight(); 268 uint w = getWidth(); 269 270 Graphics::Surface *surface = decodeNextFrame(); 271 byte *src = (byte *)surface->pixels; 272 dst += y * pitch + x; 273 274 do { 275 memcpy(dst, src, w); 276 dst += pitch; 277 src += w; 278 } while (--h); 279 280 if (hasDirtyPalette()) 281 setSystemPalette(); 282 } 283 267 284 void MoviePlayerDXA::playVideo() { 268 285 // Most of the videos included in the Amiga version, reduced the 269 286 // resoluton to 384 x 280, so require the screen to be cleared, … … 277 294 } 278 295 279 296 void MoviePlayerDXA::stopVideo() { 280 close File();297 close(); 281 298 _mixer->stopHandle(_bgSound); 282 299 } 283 300 … … 318 335 } 319 336 320 337 void MoviePlayerDXA::nextFrame() { 321 if (_bgSoundStream && _vm->_mixer->isSoundHandleActive(_bgSound) && (_vm->_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 <= (uint32)getCurFrame()) {338 if (_bgSoundStream && _vm->_mixer->isSoundHandleActive(_bgSound) && needsUpdate()) { 322 339 copyFrameToBuffer(_vm->getBackBuf(), 465, 222, _vm->_screenWidth); 323 340 return; 324 341 } 325 342 326 343 if (_vm->_interactiveVideo == TYPE_LOOPING && endOfVideo()) { 327 _fileStream->seek(_ videoInfo.firstframeOffset);328 _ videoInfo.currentFrame = -1;344 _fileStream->seek(_firstFrameOffset); 345 _curFrame = -1; 329 346 startSound(); 330 347 } 331 348 332 349 if (!endOfVideo()) { 333 decodeNextFrame();334 350 if (_vm->_interactiveVideo == TYPE_OMNITV) { 335 351 copyFrameToBuffer(_vm->getBackBuf(), 465, 222, _vm->_screenWidth); 336 352 } else if (_vm->_interactiveVideo == TYPE_LOOPING) { 337 353 copyFrameToBuffer(_vm->getBackBuf(), (_vm->_screenWidth - getWidth()) / 2, (_vm->_screenHeight - getHeight()) / 2, _vm->_screenWidth); 338 354 } 339 355 } else if (_vm->_interactiveVideo == TYPE_OMNITV) { 340 close File();356 close(); 341 357 _vm->_interactiveVideo = 0; 342 358 _vm->_variableArray[254] = 6747; 343 359 } 344 360 } 345 361 346 362 void MoviePlayerDXA::handleNextFrame() { 347 decodeNextFrame();348 363 if (processFrame()) 349 364 _vm->_system->updateScreen(); 350 365 351 366 MoviePlayer::handleNextFrame(); 352 367 } 353 368 354 void MoviePlayerDXA::setPalette(byte *pal) {355 byte palette[1024];356 byte *p = palette;357 358 for (int i = 0; i < 256; i++) {359 *p++ = *pal++;360 *p++ = *pal++;361 *p++ = *pal++;362 *p++ = 0;363 }364 365 _vm->_system->setPalette(palette, 0, 256);366 }367 368 369 bool MoviePlayerDXA::processFrame() { 369 370 Graphics::Surface *screen = _vm->_system->lockScreen(); 370 371 copyFrameToBuffer((byte *)screen->pixels, (_vm->_screenWidth - getWidth()) / 2, (_vm->_screenHeight - getHeight()) / 2, _vm->_screenWidth); 371 372 _vm->_system->unlockScreen(); 372 373 373 if ((_bgSoundStream == NULL) || ((int)(_mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 <= getCurFrame())) { 374 Common::Rational soundTime(_mixer->getSoundElapsedTime(_bgSound), 1000); 375 if ((_bgSoundStream == NULL) || ((int)(soundTime * getFrameRate()) / 1000 < getCurFrame() + 1)) { 374 376 375 377 if (_bgSoundStream && _mixer->isSoundHandleActive(_bgSound)) { 376 while (_mixer->isSoundHandleActive(_bgSound) && ( _mixer->getSoundElapsedTime(_bgSound) * getFrameRate()) / 1000 <= (uint32)getCurFrame()) {378 while (_mixer->isSoundHandleActive(_bgSound) && ((int) (soundTime * getFrameRate())) < getCurFrame()) { 377 379 _vm->_system->delayMillis(10); 380 soundTime = Common::Rational(_mixer->getSoundElapsedTime(_bgSound), 1000); 378 381 } 379 382 // In case the background sound ends prematurely, update 380 383 // _ticks so that we can still fall back on the no-sound 381 384 // sync case for the subsequent frames. 382 385 _ticks = _vm->_system->getMillis(); 383 386 } else { 384 _ticks += get FrameWaitTime();387 _ticks += getTimeToNextFrame(); 385 388 while (_vm->_system->getMillis() < _ticks) 386 389 _vm->_system->delayMillis(10); 387 390 } … … 407 410 } 408 411 409 412 bool MoviePlayerSMK::load() { 410 char videoName[20];413 Common::String videoName = Common::String::printf("%s.smk", baseName); 411 414 412 sprintf(videoName, "%s.smk", baseName);413 415 if (!loadFile(videoName)) 414 error("Failed to load video file %s", videoName );416 error("Failed to load video file %s", videoName.c_str()); 415 417 416 debug(0, "Playing video %s", videoName );418 debug(0, "Playing video %s", videoName.c_str()); 417 419 418 420 CursorMan.showMouse(false); 419 421 422 _firstFrameOffset = _fileStream->pos(); 423 420 424 return true; 421 425 } 422 426 427 void MoviePlayerSMK::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) { 428 uint h = getHeight(); 429 uint w = getWidth(); 430 431 Graphics::Surface *surface = decodeNextFrame(); 432 byte *src = (byte *)surface->pixels; 433 dst += y * pitch + x; 434 435 do { 436 memcpy(dst, src, w); 437 dst += pitch; 438 src += w; 439 } while (--h); 440 441 if (hasDirtyPalette()) 442 setSystemPalette(); 443 } 444 423 445 void MoviePlayerSMK::playVideo() { 424 446 while (!endOfVideo() && !_skipMovie && !_vm->shouldQuit()) 425 447 handleNextFrame(); 426 448 } 427 449 428 450 void MoviePlayerSMK::stopVideo() { 429 close File();451 close(); 430 452 } 431 453 432 454 void MoviePlayerSMK::startSound() { 433 455 } 434 456 435 457 void MoviePlayerSMK::handleNextFrame() { 436 decodeNextFrame();437 458 processFrame(); 438 459 439 460 MoviePlayer::handleNextFrame(); … … 441 462 442 463 void MoviePlayerSMK::nextFrame() { 443 464 if (_vm->_interactiveVideo == TYPE_LOOPING && endOfVideo()) { 444 _fileStream->seek(_ videoInfo.firstframeOffset);445 _ videoInfo.currentFrame = -1;465 _fileStream->seek(_firstFrameOffset); 466 _curFrame = -1; 446 467 } 447 468 448 469 if (!endOfVideo()) { … … 453 474 copyFrameToBuffer(_vm->getBackBuf(), (_vm->_screenWidth - getWidth()) / 2, (_vm->_screenHeight - getHeight()) / 2, _vm->_screenWidth); 454 475 } 455 476 } else if (_vm->_interactiveVideo == TYPE_OMNITV) { 456 close File();477 close(); 457 478 _vm->_interactiveVideo = 0; 458 479 _vm->_variableArray[254] = 6747; 459 480 } 460 481 } 461 482 462 void MoviePlayerSMK::setPalette(byte *pal) {463 byte palette[1024];464 byte *p = palette;465 466 for (int i = 0; i < 256; i++) {467 *p++ = *pal++;468 *p++ = *pal++;469 *p++ = *pal++;470 *p++ = 0;471 }472 473 _vm->_system->setPalette(palette, 0, 256);474 }475 476 483 bool MoviePlayerSMK::processFrame() { 477 484 Graphics::Surface *screen = _vm->_system->lockScreen(); 478 485 copyFrameToBuffer((byte *)screen->pixels, (_vm->_screenWidth - getWidth()) / 2, (_vm->_screenHeight - getHeight()) / 2, _vm->_screenWidth); 479 486 _vm->_system->unlockScreen(); 480 487 481 uint32 waitTime = get FrameWaitTime();488 uint32 waitTime = getTimeToNextFrame(); 482 489 483 490 if (!waitTime) { 484 491 warning("dropped frame %i", getCurFrame());