Ticket #8545: dxa-unification.diff
File dxa-unification.diff, 16.4 KB (added by , 18 years ago) |
---|
-
engines/scumm/he/animation_he.h
25 25 #define ANIMATION_H 26 26 27 27 #include "common/file.h" 28 #include "graphics/animation.h" 28 29 29 30 namespace Scumm { 30 31 31 32 class ScummEngine_v90he; 32 33 33 class MoviePlayer {34 class MoviePlayer : public Graphics::DXAPlayer { 34 35 ScummEngine_v90he *_vm; 35 36 36 Common::File _fd;37 uint8 *_frameBuffer1;38 uint8 *_frameBuffer2;39 uint16 _width;40 uint16 _height;41 uint16 _framesCount;42 uint32 _framesPerSec;43 uint16 _frameNum;44 uint32 _frameSize;45 uint32 _frameTicks;46 47 37 uint32 _flags; 48 38 uint32 _wizResNum; 49 39 50 40 public: 51 41 MoviePlayer(ScummEngine_v90he *vm); 52 ~MoviePlayer();53 42 54 int getWidth();55 int getHeight();56 int getCurFrame();57 int getFrameCount();58 43 int getImageNum(); 59 44 int load(const char *filename, int flags, int image = 0); 60 45 61 46 void handleNextFrame(); 62 47 void close(); 63 48 64 private: 65 void copyFrame(byte *dst, uint x, uint y); 66 void decodeFrame(); 67 void decodeZlib(uint8 *data, int size, int totalSize); 49 protected: 50 virtual void setPalette(byte *pal); 68 51 }; 69 52 70 53 } // End of namespace Simon -
engines/scumm/he/animation_he.cpp
26 26 #include "scumm/he/animation_he.h" 27 27 #include "scumm/he/intern_he.h" 28 28 29 #ifdef USE_ZLIB30 #include <zlib.h>31 #endif32 33 29 namespace Scumm { 34 30 35 31 MoviePlayer::MoviePlayer(ScummEngine_v90he *vm) 36 : _vm(vm) {32 : DXAPlayer(), _vm(vm) { 37 33 38 _frameBuffer1 = 0;39 _frameBuffer2 = 0;40 41 _width = 0;42 _height = 0;43 44 _frameSize = 0;45 _framesCount = 0;46 _frameNum = 0;47 _framesPerSec = 0;48 _frameTicks = 0;49 50 34 _flags = 0; 51 35 _wizResNum = 0; 52 36 } 53 37 54 MoviePlayer::~MoviePlayer() {55 }56 57 int MoviePlayer::getWidth() {58 if (_fd.isOpen() == false)59 return 0;60 return _width;61 }62 63 int MoviePlayer::getHeight() {64 if (_fd.isOpen() == false)65 return 0;66 return _height;67 }68 69 int MoviePlayer::getCurFrame() {70 if (_fd.isOpen() == false)71 return -1;72 return _frameNum;73 }74 75 int MoviePlayer::getFrameCount() {76 if (_fd.isOpen() == false)77 return 0;78 return _framesCount;79 }80 81 38 int MoviePlayer::getImageNum() { 82 39 if (_fd.isOpen() == false) 83 40 return 0; … … 174 131 assert(dstPtr); 175 132 dst = _vm->findWrappedBlock(MKID_BE('WIZD'), dstPtr, 0, 0); 176 133 assert(dst); 177 copyFrame(dst, 0, 0 );134 copyFrame(dst, 0, 0, _vm->_screenWidth); 178 135 } else if (_flags & 1) { 179 136 dst = pvs->getBackPixels(0, 0); 180 copyFrame(dst, 0, 0 );137 copyFrame(dst, 0, 0, _vm->_screenWidth); 181 138 182 139 Common::Rect imageRect(_width, _height); 183 140 _vm->gdi.copyVirtScreenBuffers(imageRect); 184 141 } else { 185 142 dst = pvs->getPixels(0, 0); 186 copyFrame(dst, 0, 0 );143 copyFrame(dst, 0, 0, _vm->_screenWidth); 187 144 188 145 _vm->markRectAsDirty(kMainVirtScreen, 0, 0, _width, _height); 189 146 } … … 194 151 } 195 152 } 196 153 197 void MoviePlayer::copyFrame(byte *dst, uint x, uint y) { 198 uint h = _height; 199 uint w = _width; 200 201 dst += y * _vm->_screenWidth + x; 202 byte *src = _frameBuffer1; 203 204 do { 205 memcpy(dst, src, w); 206 dst += _vm->_screenWidth; 207 src += _width; 208 } while (--h); 154 void MoviePlayer::setPalette(byte *pal) { 155 _vm->setPaletteFromPtr(pal, 256); 209 156 } 210 157 211 void MoviePlayer::decodeZlib(uint8 *data, int size, int totalSize) {212 #ifdef USE_ZLIB213 uint8 *temp = (uint8 *)malloc(size);214 if (temp) {215 memcpy(temp, data, size);216 z_stream d_stream;217 d_stream.zalloc = (alloc_func)0;218 d_stream.zfree = (free_func)0;219 d_stream.opaque = (voidpf)0;220 d_stream.next_in = temp;221 d_stream.avail_in = size;222 d_stream.total_in = size;223 d_stream.next_out = data;224 d_stream.avail_out = totalSize;225 inflateInit(&d_stream);226 inflate(&d_stream, Z_FINISH);227 inflateEnd(&d_stream);228 free(temp);229 }230 #endif231 }232 233 void MoviePlayer::decodeFrame() {234 uint32 tag;235 236 tag = _fd.readUint32BE();237 if (tag == MKID_BE('CMAP')) {238 uint8 rgb[768];239 240 _fd.read(rgb, ARRAYSIZE(rgb));241 _vm->setPaletteFromPtr(rgb, 256);242 }243 244 tag = _fd.readUint32BE();245 if (tag == MKID_BE('FRAM')) {246 uint8 type = _fd.readByte();247 uint32 size = _fd.readUint32BE();248 249 _fd.read(_frameBuffer2, size);250 251 switch (type) {252 case 2:253 case 3:254 decodeZlib(_frameBuffer2, size, _frameSize);255 break;256 default:257 error("decodeFrame: Unknown compression type %d", type);258 }259 if (type == 2) {260 memcpy(_frameBuffer1, _frameBuffer2, _frameSize);261 } else {262 for (int j = 0; j < _height; ++j) {263 for (int i = 0; i < _width; ++i) {264 const int offs = j * _width + i;265 _frameBuffer1[offs] ^= _frameBuffer2[offs];266 }267 }268 }269 }270 }271 272 158 } // End of namespace Simon -
engines/simon/animation.h
27 27 #include "common/file.h" 28 28 #include "common/stream.h" 29 29 30 #include "graphics/animation.h" 30 31 #include "sound/mixer.h" 31 32 32 33 namespace Simon { 33 34 34 35 class SimonEngine; 35 36 36 class MoviePlayer {37 class MoviePlayer : public Graphics::DXAPlayer { 37 38 SimonEngine *_vm; 38 39 39 40 Audio::Mixer *_mixer; … … 45 46 bool _playing; 46 47 bool _leftButtonDown; 47 48 bool _rightButtonDown; 48 Common::File _fd;49 uint8 *_frameBuffer1;50 uint8 *_frameBuffer2;51 uint16 _width;52 uint16 _height;53 uint16 _framesCount;54 uint32 _framesPerSec;55 uint16 _frameNum;56 uint32 _frameSize;57 49 uint16 _frameSkipped; 58 uint32 _frameTicks;59 50 uint32 _ticks; 60 51 61 52 char baseName[40]; … … 63 54 uint8 _sequenceNum; 64 55 public: 65 56 MoviePlayer(SimonEngine *vm, Audio::Mixer *mixer); 66 ~MoviePlayer();67 57 68 58 bool load(const char *filename); 69 59 void play(); 70 60 void nextFrame(); 61 protected: 62 virtual void setPalette(byte *pal); 71 63 private: 72 64 void playOmniTV(); 73 65 void close(); 74 66 75 void copyFrame(byte *dst, uint x, uint y);76 void decodeFrame();77 67 void handleNextFrame(); 78 68 void processFrame(); 79 69 void startSound(); 80 void decodeZlib(uint8 *data, int size, int totalSize);81 70 }; 82 71 83 72 } // End of namespace Simon -
engines/simon/animation.cpp
35 35 #include "sound/audiostream.h" 36 36 #include "sound/wave.h" 37 37 38 39 #ifdef USE_ZLIB40 #include <zlib.h>41 #endif42 43 38 namespace Simon { 44 39 45 40 MoviePlayer::MoviePlayer(SimonEngine *vm, Audio::Mixer *mixer) 46 : _vm(vm), _mixer(mixer) {41 : DXAPlayer(), _vm(vm), _mixer(mixer) { 47 42 _omniTV = false; 48 43 _playing = false; 49 44 50 45 _leftButtonDown = false; 51 46 _rightButtonDown = false; 52 47 53 _frameBuffer1 = 0;54 _frameBuffer2 = 0;55 56 _width = 0;57 _height = 0;58 59 _frameSize = 0;60 _framesCount = 0;61 _frameNum = 0;62 _framesPerSec = 0;63 _frameTicks = 0;64 48 _frameSkipped = 0; 65 49 66 50 memset(baseName, 0, sizeof(baseName)); … … 69 53 _ticks = 0; 70 54 } 71 55 72 MoviePlayer::~MoviePlayer() {73 }74 75 56 bool MoviePlayer::load(const char *filename) { 76 57 char videoName[20]; 77 58 uint32 tag; … … 276 257 } 277 258 278 259 if (_mixer->isSoundHandleActive(_bgSound) && (_mixer->getSoundElapsedTime(_bgSound) * _framesPerSec) / 1000 < _frameNum) { 279 copyFrame(_vm->getBackBuf(), 465, 222 );260 copyFrame(_vm->getBackBuf(), 465, 222, _vm->_screenWidth); 280 261 return; 281 262 } 282 263 283 264 if (_frameNum < _framesCount) { 284 265 decodeFrame(); 285 copyFrame(_vm->getBackBuf(), 465, 222 );266 copyFrame(_vm->getBackBuf(), 465, 222, _vm->_screenWidth); 286 267 _frameNum++; 287 268 } else { 288 269 _omniTV = false; … … 332 313 } 333 314 } 334 315 335 void MoviePlayer:: copyFrame(byte *dst, uint x, uint y) {336 uint h = _height;337 uint w = _width;316 void MoviePlayer::setPalette(byte *pal) { 317 byte palette[1024]; 318 byte *p = palette; 338 319 339 dst += y * _vm->_screenWidth + x; 340 byte *src = _frameBuffer1; 341 342 do { 343 memcpy(dst, src, w); 344 dst += _vm->_screenWidth; 345 src += _width; 346 } while (--h); 347 } 348 349 void MoviePlayer::decodeZlib(uint8 *data, int size, int totalSize) { 350 #ifdef USE_ZLIB 351 uint8 *temp = (uint8 *)malloc(size); 352 if (temp) { 353 memcpy(temp, data, size); 354 z_stream d_stream; 355 d_stream.zalloc = (alloc_func)0; 356 d_stream.zfree = (free_func)0; 357 d_stream.opaque = (voidpf)0; 358 d_stream.next_in = temp; 359 d_stream.avail_in = size; 360 d_stream.total_in = size; 361 d_stream.next_out = data; 362 d_stream.avail_out = totalSize; 363 inflateInit(&d_stream); 364 inflate(&d_stream, Z_FINISH); 365 inflateEnd(&d_stream); 366 free(temp); 320 for (int i = 0; i <= 256; i++) { 321 *p++ = *pal++; 322 *p++ = *pal++; 323 *p++ = *pal++; 324 *p++ = 0; 367 325 } 368 #endif369 }370 326 371 void MoviePlayer::decodeFrame() { 372 uint32 tag; 373 374 tag = _fd.readUint32BE(); 375 if (tag == MKID_BE('CMAP')) { 376 uint8 rgb[768]; 377 byte palette[1024]; 378 byte *p = palette; 379 380 _fd.read(rgb, ARRAYSIZE(rgb)); 381 for (int i = 0; i <= 256; i++) { 382 *p++ = rgb[i * 3 + 0]; 383 *p++ = rgb[i * 3 + 1]; 384 *p++ = rgb[i * 3 + 2]; 385 *p++ = 0; 386 } 387 _vm->_system->setPalette(palette, 0, 256); 388 } 389 390 tag = _fd.readUint32BE(); 391 if (tag == MKID_BE('FRAM')) { 392 uint8 type = _fd.readByte(); 393 uint32 size = _fd.readUint32BE(); 394 debug(5, "frame %d type %d size %d", _frameNum, type, size); 395 396 _fd.read(_frameBuffer2, size); 397 398 switch (type) { 399 case 2: 400 case 3: 401 decodeZlib(_frameBuffer2, size, _frameSize); 402 break; 403 default: 404 error("decodeFrame: Unknown compression type %d", type); 405 } 406 if (type == 2) { 407 memcpy(_frameBuffer1, _frameBuffer2, _frameSize); 408 } else { 409 for (int j = 0; j < _height; ++j) { 410 for (int i = 0; i < _width; ++i) { 411 const int offs = j * _width + i; 412 _frameBuffer1[offs] ^= _frameBuffer2[offs]; 413 } 414 } 415 } 416 } 327 _vm->_system->setPalette(palette, 0, 256); 417 328 } 418 329 419 330 void MoviePlayer::processFrame() { 420 copyFrame(_vm->getFrontBuf(), (_vm->_screenWidth - _width) / 2, (_vm->_screenHeight - _height) / 2 );331 copyFrame(_vm->getFrontBuf(), (_vm->_screenWidth - _width) / 2, (_vm->_screenHeight - _height) / 2, _vm->_screenWidth); 421 332 _vm->_system->copyRectToScreen(_vm->getFrontBuf(), _vm->_screenWidth, 0, 0, _vm->_screenWidth, _vm->_screenHeight); 422 333 423 334 if ((_bgSoundStream == NULL) || ((int)(_mixer->getSoundElapsedTime(_bgSound) * _framesPerSec) / 1000 < _frameNum + 1) || -
graphics/animation.cpp
21 21 */ 22 22 23 23 #include "common/stdafx.h" 24 #include "common/endian.h" 24 25 #include "graphics/animation.h" 25 26 #include "sound/audiostream.h" 26 27 #include "common/config-manager.h" … … 29 30 #include "common/util.h" 30 31 #include "graphics/scaler/intern.h" 31 32 33 #ifdef USE_ZLIB 34 #include <zlib.h> 35 #endif 36 32 37 namespace Graphics { 33 38 34 39 BaseAnimationState::BaseAnimationState(Audio::Mixer *snd, OSystem *sys, int width, int height) … … 680 685 _sys->updateScreen(); 681 686 } 682 687 688 DXAPlayer::DXAPlayer() { 689 _frameBuffer1 = 0; 690 _frameBuffer2 = 0; 691 692 _width = 0; 693 _height = 0; 694 695 _frameSize = 0; 696 _framesCount = 0; 697 _frameNum = 0; 698 _framesPerSec = 0; 699 _frameTicks = 0; 700 } 701 702 DXAPlayer::~DXAPlayer() { 703 } 704 705 int DXAPlayer::getWidth() { 706 if (_fd.isOpen() == false) 707 return 0; 708 return _width; 709 } 710 711 int DXAPlayer::getHeight() { 712 if (_fd.isOpen() == false) 713 return 0; 714 return _height; 715 } 716 717 int DXAPlayer::getCurFrame() { 718 if (_fd.isOpen() == false) 719 return -1; 720 return _frameNum; 721 } 722 723 int DXAPlayer::getFrameCount() { 724 if (_fd.isOpen() == false) 725 return 0; 726 return _framesCount; 727 } 728 729 void DXAPlayer::copyFrame(byte *dst, uint x, uint y, uint pitch) { 730 uint h = _height; 731 uint w = _width; 732 733 dst += y * pitch + x; 734 byte *src = _frameBuffer1; 735 736 do { 737 memcpy(dst, src, w); 738 dst += pitch; 739 src += _width; 740 } while (--h); 741 } 742 743 void DXAPlayer::decodeZlib(byte *data, int size, int totalSize) { 744 #ifdef USE_ZLIB 745 byte *temp = (byte *)malloc(size); 746 if (temp) { 747 memcpy(temp, data, size); 748 749 z_stream d_stream; 750 d_stream.zalloc = (alloc_func)0; 751 d_stream.zfree = (free_func)0; 752 d_stream.opaque = (voidpf)0; 753 d_stream.next_in = temp; 754 d_stream.avail_in = size; 755 d_stream.total_in = size; 756 d_stream.next_out = data; 757 d_stream.avail_out = totalSize; 758 inflateInit(&d_stream); 759 inflate(&d_stream, Z_FINISH); 760 inflateEnd(&d_stream); 761 free(temp); 762 } 763 #endif 764 } 765 766 #define BLOCKW 4 767 #define BLOCKH 4 768 769 void DXAPlayer::decode12(byte *data, int size, int totalSize) { 770 #ifdef USE_ZLIB 771 /* decompress the input data */ 772 decodeZlib(data, size, totalSize); 773 774 byte *dat = data; 775 byte *frame2 = (byte *)malloc(totalSize); 776 777 memcpy(frame2, _frameBuffer1, totalSize); 778 779 for (int by = 0; by < _height; by += BLOCKH) { 780 for (int bx = 0; bx < _width; bx += BLOCKW) { 781 byte type = *dat++; 782 byte *b2 = frame2 + bx + by * _width; 783 784 switch (type) { 785 case 0: 786 break; 787 case 10: 788 case 11: 789 case 12: 790 case 13: 791 case 14: 792 case 15: 793 case 1: { 794 unsigned short diffMap; 795 if (type >= 10 && type <= 15) { 796 static const struct { uint8 sh1, sh2; } shiftTbl[6] = { 797 {0, 0}, {8, 0}, {8, 8}, {8, 4}, {4, 0}, {4, 4} 798 }; 799 diffMap = ((*dat & 0xF0) << shiftTbl[type-10].sh1) | 800 ((*dat & 0x0F) << shiftTbl[type-10].sh2); 801 dat++; 802 } else { 803 diffMap = *(unsigned short*)dat; 804 dat += 2; 805 } 806 807 for (int yc = 0; yc < BLOCKH; yc++) { 808 for (int xc = 0; xc < BLOCKW; xc++) { 809 if (diffMap & 0x8000) { 810 b2[xc] = *dat++; 811 } 812 diffMap <<= 1; 813 } 814 b2 += _width; 815 } 816 break; 817 } 818 case 2: { 819 byte color = *dat++; 820 821 for (int yc = 0; yc < BLOCKH; yc++) { 822 for (int xc = 0; xc < BLOCKW; xc++) { 823 b2[xc] = color; 824 } 825 b2 += _width; 826 } 827 break; 828 } 829 case 3: { 830 for (int yc = 0; yc < BLOCKH; yc++) { 831 for (int xc = 0; xc < BLOCKW; xc++) { 832 b2[xc] = *dat++; 833 } 834 b2 += _width; 835 } 836 break; 837 } 838 case 4: { 839 byte mbyte = *dat++; 840 int mx = (mbyte >> 4) & 0x07; 841 if (mbyte & 0x80) 842 mx = -mx; 843 int my = mbyte & 0x07; 844 if (mbyte & 0x08) 845 my = -my; 846 byte *b1 = _frameBuffer1 + (bx+mx) + (by+my) * _width; 847 for (int yc = 0; yc < BLOCKH; yc++) { 848 memcpy(b2, b1, BLOCKW); 849 b1 += _width; 850 b2 += _width; 851 } 852 break; 853 } 854 case 5: 855 break; 856 } 857 } 858 } 859 860 memcpy(data, frame2, totalSize); 861 free(frame2); 862 #endif 863 } 864 865 void DXAPlayer::decodeFrame() { 866 uint32 tag; 867 868 tag = _fd.readUint32BE(); 869 if (tag == MKID_BE('CMAP')) { 870 byte rgb[768]; 871 872 _fd.read(rgb, ARRAYSIZE(rgb)); 873 setPalette(rgb); 874 } 875 876 tag = _fd.readUint32BE(); 877 if (tag == MKID_BE('FRAM')) { 878 byte type = _fd.readByte(); 879 uint32 size = _fd.readUint32BE(); 880 881 _fd.read(_frameBuffer2, size); 882 883 switch (type) { 884 case 2: 885 case 3: 886 decodeZlib(_frameBuffer2, size, _frameSize); 887 break; 888 #if 0 889 case 4: 890 case 5: 891 decode0(_frameBuffer2, size); 892 break; 893 case 6: 894 case 7: 895 decode2(_frameBuffer2, size, _frameSize); 896 break; 897 #endif 898 case 12: 899 decode12(_frameBuffer2, size, _frameSize); 900 break; 901 default: 902 error("decodeFrame: Unknown compression type %d", type); 903 } 904 if (type == 2 || type == 4 || type == 6 || type == 12) { 905 memcpy(_frameBuffer1, _frameBuffer2, _frameSize); 906 } else { 907 for (int j = 0; j < _height; ++j) { 908 for (int i = 0; i < _width; ++i) { 909 const int offs = j * _width + i; 910 _frameBuffer1[offs] ^= _frameBuffer2[offs]; 911 } 912 } 913 } 914 } 915 } 916 683 917 } // End of namespace Graphics -
graphics/animation.h
24 24 #define GRAPHICS_ANIMATION_H 25 25 26 26 #include "common/scummsys.h" 27 #include "common/file.h" 28 27 29 #include "sound/mixer.h" 28 30 29 31 namespace Audio { … … 156 158 #endif 157 159 }; 158 160 161 class DXAPlayer { 162 protected: 163 Common::File _fd; 159 164 165 byte *_frameBuffer1; 166 byte *_frameBuffer2; 167 uint16 _width; 168 uint16 _height; 169 uint16 _framesCount; 170 uint32 _framesPerSec; 171 uint16 _frameNum; 172 uint32 _frameSize; 173 uint32 _frameTicks; 174 175 public: 176 DXAPlayer(); 177 virtual ~DXAPlayer(); 178 179 int getWidth(); 180 int getHeight(); 181 int getCurFrame(); 182 int getFrameCount(); 183 184 protected: 185 virtual void setPalette(byte *pal) = 0; 186 187 void copyFrame(byte *dst, uint x, uint y, uint pitch); 188 void decodeFrame(); 189 void decodeZlib(byte *data, int size, int totalSize); 190 void decode12(byte *data, int size, int totalSize); 191 }; 192 160 193 } // End of namespace Graphics 161 194 162 195 #endif