Ticket #8607: vqa_player_cleanup.diff
File vqa_player_cleanup.diff, 7.0 KB (added by , 18 years ago) |
---|
-
kyra/screen.h
225 225 226 226 // decoding functions 227 227 static void decodeFrame3(const uint8 *src, uint8 *dst, uint32 size); 228 static voiddecodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize);228 static uint32 decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize); 229 229 static void decodeFrameDelta(uint8 *dst, const uint8 *src); 230 230 static void decodeFrameDeltaPage(uint8 *dst, const uint8 *src, const int pitch, bool noXor); 231 231 -
kyra/vqa.cpp
96 96 return tag; 97 97 } 98 98 99 // Chunk types ending in a 'Z' are decoded using this function.100 101 int VQAMovie::decodeFormat80(byte *inbuf, byte *outbuf) {102 byte *src = inbuf;103 byte *dst = outbuf;104 105 while (1) {106 int relPos, pos;107 int count;108 byte color;109 int i;110 111 byte command = *src++;112 113 switch (command) {114 case 0x80:115 return dst - outbuf;116 117 case 0xFF:118 /* 11111111 <count> <pos> */119 count = src[0] | (src[1] << 8);120 pos = src[2] | (src[3] << 8);121 src += 4;122 for (i = 0; i < count; i++)123 dst[i] = outbuf[i + pos];124 break;125 126 case 0xFE:127 /* 11111110 <count> <color> */128 count = src[0] | (src[1] << 8);129 color = src[2];130 src += 3;131 memset(dst, color, count);132 break;133 134 default:135 if (command >= 0xC0) {136 /* 11 <count - 3> <pos> */137 count = (command & 0x3F) + 3;138 pos = src[0] | (src[1] << 8);139 src += 2;140 for (i = 0; i < count; i++)141 dst[i] = outbuf[pos + i];142 } else if (command >= 0x80) {143 /* 10 <count> */144 count = command & 0x3F;145 memcpy(dst, src, count);146 src += count;147 } else {148 /* 0 <count - 3> <relative pos> */149 count = ((command & 0x70) >> 4) + 3;150 relPos = ((command & 0x0F) << 8) | src[0];151 src++;152 for (i = 0; i < count; i++)153 dst[i] = dst[i - relPos];154 }155 break;156 }157 158 dst += count;159 }160 }161 162 inline int16 clip8BitSample(int16 sample) {163 if (sample > 255)164 return 255;165 if (sample < 0)166 return 0;167 return sample;168 }169 170 99 void VQAMovie::decodeSND1(byte *inbuf, uint32 insize, byte *outbuf, uint32 outsize) { 171 100 const int8 WSTable2Bit[] = { -2, -1, 0, 1 }; 172 101 const int8 WSTable4Bit[] = { … … 206 135 code = *inbuf++; 207 136 208 137 curSample += WSTable4Bit[code & 0x0f]; 209 curSample = clip8BitSample(curSample);138 curSample = CLIP<int16>(curSample, 0, 255); 210 139 *outbuf++ = curSample; 211 140 212 141 curSample += WSTable4Bit[code >> 4]; 213 curSample = clip8BitSample(curSample);142 curSample = CLIP<int16>(curSample, 0, 255); 214 143 *outbuf++ = curSample; 215 144 216 145 outsize -= 2; … … 221 150 code = *inbuf++; 222 151 223 152 curSample += WSTable2Bit[code & 0x03]; 224 curSample = clip8BitSample(curSample);153 curSample = CLIP<int16>(curSample, 0, 255); 225 154 *outbuf++ = curSample; 226 155 227 156 curSample += WSTable2Bit[(code >> 2) & 0x03]; 228 curSample = clip8BitSample(curSample);157 curSample = CLIP<int16>(curSample, 0, 255); 229 158 *outbuf++ = curSample; 230 159 231 160 curSample += WSTable2Bit[(code >> 4) & 0x03]; 232 curSample = clip8BitSample(curSample);161 curSample = CLIP<int16>(curSample, 0, 255); 233 162 *outbuf++ = curSample; 234 163 235 164 curSample += WSTable2Bit[(code >> 6) & 0x03]; 236 curSample = clip8BitSample(curSample);165 curSample = CLIP<int16>(curSample, 0, 255); 237 166 *outbuf++ = curSample; 238 167 239 168 outsize -= 4; … … 325 254 _frameInfo = new uint32[_header.numFrames]; 326 255 _frame = new byte[_header.width * _header.height]; 327 256 328 size = 0xf00 * _header.blockW * _header.blockH;329 _codeBook = new byte[ size];330 _partialCodeBook = new byte[ size];331 memset(_codeBook, 0, size);332 memset(_partialCodeBook, 0, size);257 _codeBookSize = 0xf00 * _header.blockW * _header.blockH; 258 _codeBook = new byte[_codeBookSize]; 259 _partialCodeBook = new byte[_codeBookSize]; 260 memset(_codeBook, 0, _codeBookSize); 261 memset(_partialCodeBook, 0, _codeBookSize); 333 262 334 263 _numVectorPointers = (_header.width / _header.blockW) * (_header.height * _header.blockH); 335 264 _vectorPointers = new uint16[_numVectorPointers]; … … 427 356 428 357 _frameInfo = NULL; 429 358 _frame = NULL; 359 _codeBookSize = 0; 430 360 _codeBook = NULL; 431 361 _partialCodeBook = NULL; 432 362 _vectorPointers = NULL; … … 513 443 case MKID_BE('CBFZ'): // Full codebook 514 444 inbuf = (byte *)allocBuffer(0, size); 515 445 _file.read(inbuf, size); 516 decodeFormat80(inbuf, _codeBook);446 Screen::decodeFrame4(inbuf, _codeBook, _codeBookSize); 517 447 break; 518 448 519 449 case MKID_BE('CBP0'): // Partial codebook … … 538 468 case MKID_BE('CPLZ'): // Palette 539 469 inbuf = (byte *)allocBuffer(0, size); 540 470 _file.read(inbuf, size); 541 size = decodeFormat80(inbuf, _vm->screen()->_currentPalette);471 Screen::decodeFrame4(inbuf, _vm->screen()->_currentPalette, 768); 542 472 break; 543 473 544 474 case MKID_BE('VPT0'): // Frame data … … 553 483 outbuf = (byte *)allocBuffer(1, 2 * _numVectorPointers); 554 484 555 485 _file.read(inbuf, size); 556 size = decodeFormat80(inbuf, outbuf);486 size = Screen::decodeFrame4(inbuf, outbuf, 2 * _numVectorPointers); 557 487 558 488 assert(size / 2 <= _numVectorPointers); 559 489 … … 614 544 615 545 if (_numPartialCodeBooks == _header.cbParts) { 616 546 if (_compressedCodeBook) { 617 decodeFormat80(_partialCodeBook, _codeBook);547 Screen::decodeFrame4(_partialCodeBook, _codeBook, _codeBookSize); 618 548 } else { 619 549 memcpy(_codeBook, _partialCodeBook, _partialCodeBookSize); 620 550 } … … 633 563 634 564 startTick = _system->getMillis(); 635 565 636 // First, handle any sound chunk that ap ears before the first frame.566 // First, handle any sound chunk that appears before the first frame. 637 567 // At least in some versions, it will contain half a second of audio, 638 568 // presumably to lessen the risk of audio underflow. 639 569 // -
kyra/screen.cpp
1547 1547 } 1548 1548 } 1549 1549 1550 voidScreen::decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize) {1550 uint32 Screen::decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize) { 1551 1551 debugC(9, kDebugLevelScreen, "Screen::decodeFrame4(%p, %p, %d)", (const void *)src, (const void *)dst, dstSize); 1552 1552 uint8 *dstOrig = dst; 1553 1553 uint8 *dstEnd = dst + dstSize; … … 1595 1595 break; 1596 1596 } 1597 1597 } 1598 return dst - dstOrig; 1598 1599 } 1599 1600 1600 1601 void Screen::decodeFrameDelta(uint8 *dst, const uint8 *src) { -
kyra/vqa.h
91 91 void *allocBuffer(int num, uint32 size); 92 92 void freeBuffers(); 93 93 94 int decodeFormat80(byte *inbuf, byte *outbuf);95 94 void decodeSND1(byte *inbuf, uint32 insize, byte *outbuf, uint32 outsize); 96 95 97 96 void displayFrame(uint frameNum); … … 100 99 101 100 VQAHeader _header; 102 101 uint32 *_frameInfo; 102 uint32 _codeBookSize; 103 103 byte *_codeBook; 104 104 byte *_partialCodeBook; 105 105 bool _compressedCodeBook;