Ticket #3366: codec47.patch
File codec47.patch, 8.1 KB (added by , 16 years ago) |
---|
-
engines/scumm/smush/codec47.cpp
33 33 34 34 #if defined(SCUMM_NEED_ALIGNMENT) 35 35 36 #define COPY_ 4X1_LINE(dst, src) \36 #define COPY_2X1_LINE(dst, src) \ 37 37 do { \ 38 38 (dst)[0] = (src)[0]; \ 39 39 (dst)[1] = (src)[1]; \ 40 (dst)[2] = (src)[2]; \41 (dst)[3] = (src)[3]; \42 40 } while (0) 43 41 44 #define COPY_2X1_LINE(dst, src) \42 #define FILL_2X1_LINE(dst, val) \ 45 43 do { \ 46 (dst)[0] = (src)[0]; \47 (dst)[1] = (src)[1]; \44 (dst)[0] = val; \ 45 (dst)[1] = val; \ 48 46 } while (0) 49 47 50 51 48 #else /* SCUMM_NEED_ALIGNMENT */ 52 49 53 #define COPY_4X1_LINE(dst, src) \54 *(uint32 *)(dst) = *(const uint32 *)(src)55 56 50 #define COPY_2X1_LINE(dst, src) \ 57 51 *(uint16 *)(dst) = *(const uint16 *)(src) 58 52 53 #define FILL_2X1_LINE(dst, val) \ 54 *(uint16 *)(dst) = (val) << 8 | (val) 55 59 56 #endif 60 57 58 #define COPY_4X1_LINE(dst, src) \ 59 *(uint32 *)(dst) = *(const uint32 *)(src) 60 61 61 #define FILL_4X1_LINE(dst, val) \ 62 do { \ 63 (dst)[0] = val; \ 64 (dst)[1] = val; \ 65 (dst)[2] = val; \ 66 (dst)[3] = val; \ 67 } while (0) 62 *(uint32 *)(dst) = (val) << 24 | (val) << 16 | (val) << 8 | (val) 68 63 69 #define FILL_2X1_LINE(dst, val) \70 do { \71 (dst)[0] = val; \72 (dst)[1] = val; \73 } while (0)74 64 65 75 66 static const int8 codec47_table_small1[] = { 76 67 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1, 77 68 }; … … 362 353 _offset1,_offset2,_tableSmall) 363 354 364 355 #else 365 void Codec47Decoder::level3(byte *d_dst) { 366 int32 tmp; 367 byte code = *_d_src++; 356 void Codec47Decoder::level3(byte *d_dst, const int pitch, uint16 &valA, uint16 &valB) { 357 const byte code = *_d_src++; 368 358 369 359 if (code < 0xF8) { 370 tmp = _table[code] + _offset1; 371 COPY_2X1_LINE(d_dst, d_dst + tmp); 372 COPY_2X1_LINE(d_dst + _d_pitch, d_dst + _d_pitch + tmp); 360 const int tmp = _table[code] + _offset1; 361 // FIXME: The following read might be misaligned. Problem??? 362 valA = *(const uint16 *)(d_dst + tmp); 363 valB = *(const uint16 *)(d_dst + tmp + pitch); 373 364 } else if (code == 0xFF) { 374 COPY_2X1_LINE(d_dst, _d_src + 0); 375 COPY_2X1_LINE(d_dst + _d_pitch, _d_src + 2); 365 // FIXME: The following read might be misaligned. Problem??? 366 valA = *(const uint16 *)(_d_src + 0); 367 valB = *(const uint16 *)(_d_src + 2); 376 368 _d_src += 4; 377 369 } else if (code == 0xFE) { 378 byte t = *_d_src++; 379 FILL_2X1_LINE(d_dst, t); 380 FILL_2X1_LINE(d_dst + _d_pitch, t); 370 const byte t = *_d_src++; 371 valA = valB = (t << 8) | t; 381 372 } else if (code == 0xFC) { 382 tmp = _offset2; 383 COPY_2X1_LINE(d_dst, d_dst + tmp); 384 COPY_2X1_LINE(d_dst + _d_pitch, d_dst + _d_pitch + tmp); 373 const int tmp = _offset2; 374 // FIXME: The following read might be misaligned. Problem??? 375 valA = *(const uint16 *)(d_dst + tmp); 376 valB = *(const uint16 *)(d_dst + tmp + pitch); 385 377 } else { 386 byte t = _paramPtr[code]; 387 FILL_2X1_LINE(d_dst, t); 388 FILL_2X1_LINE(d_dst + _d_pitch, t); 378 const byte t = _paramPtr[code]; 379 valA = valB = (t << 8) | t; 389 380 } 390 381 } 391 382 392 void Codec47Decoder::level2(byte *d_dst) { 393 int32 tmp; 394 byte code = *_d_src++; 395 int i; 383 void Codec47Decoder::level2(byte *d_dst, const int pitch) { 384 const byte code = *_d_src++; 396 385 397 386 if (code < 0xF8) { 398 tmp = _table[code] + _offset1;399 for (i = 0; i < 4; i++) {387 const int tmp = _table[code] + _offset1; 388 for (int i = 0; i < 4; i++) { 400 389 COPY_4X1_LINE(d_dst, d_dst + tmp); 401 d_dst += _d_pitch;390 d_dst += pitch; 402 391 } 403 392 } else if (code == 0xFF) { 404 level3(d_dst); 405 d_dst += 2; 406 level3(d_dst); 407 d_dst += _d_pitch * 2 - 2; 408 level3(d_dst); 409 d_dst += 2; 410 level3(d_dst); 393 uint16 valA1, valB1, valA2, valB2; 394 395 level3(d_dst, pitch, valA1, valB1); 396 level3(d_dst + 2, pitch, valA2, valB2); 397 #ifdef SCUMM_BIG_ENDIAN 398 *(uint32 *)d_dst = ((uint32)valA1 << 16) | (uint32)valA2; 399 *(uint32 *)(d_dst + pitch) = ((uint32)valB1 << 16) | (uint32)valB2; 400 #else 401 *(uint32 *)d_dst = ((uint32)valA2 << 16) | (uint32)valA1; 402 *(uint32 *)(d_dst + pitch) = ((uint32)valB2 << 16) | (uint32)valB1; 403 #endif 404 405 d_dst += pitch * 2; 406 407 level3(d_dst, pitch, valA1, valB1); 408 level3(d_dst + 2, pitch, valA2, valB2); 409 #ifdef SCUMM_BIG_ENDIAN 410 *(uint32 *)d_dst = ((uint32)valA1 << 16) | (uint32)valA2; 411 *(uint32 *)(d_dst + pitch) = ((uint32)valB1 << 16) | (uint32)valB2; 412 #else 413 *(uint32 *)d_dst = ((uint32)valA2 << 16) | (uint32)valA1; 414 *(uint32 *)(d_dst + pitch) = ((uint32)valB2 << 16) | (uint32)valB1; 415 #endif 411 416 } else if (code == 0xFE) { 412 byte t = *_d_src++;413 for (i = 0; i < 4; i++) {417 const byte t = *_d_src++; 418 for (int i = 0; i < 4; i++) { 414 419 FILL_4X1_LINE(d_dst, t); 415 d_dst += _d_pitch;420 d_dst += pitch; 416 421 } 417 422 } else if (code == 0xFD) { 418 423 byte *tmp_ptr = _tableSmall + *_d_src++ * 128; … … 431 436 tmp_ptr2++; 432 437 } 433 438 } else if (code == 0xFC) { 434 tmp = _offset2;435 for (i = 0; i < 4; i++) {439 const int tmp = _offset2; 440 for (int i = 0; i < 4; i++) { 436 441 COPY_4X1_LINE(d_dst, d_dst + tmp); 437 d_dst += _d_pitch;442 d_dst += pitch; 438 443 } 439 444 } else { 440 byte t = _paramPtr[code];441 for (i = 0; i < 4; i++) {445 const byte t = _paramPtr[code]; 446 for (int i = 0; i < 4; i++) { 442 447 FILL_4X1_LINE(d_dst, t); 443 d_dst += _d_pitch;448 d_dst += pitch; 444 449 } 445 450 } 446 451 } 447 452 448 void Codec47Decoder::level1(byte *d_dst) { 449 int32 tmp, tmp2; 450 byte code = *_d_src++; 451 int i; 453 void Codec47Decoder::level1(byte *d_dst, const int pitch) { 454 const byte code = *_d_src++; 452 455 453 456 if (code < 0xF8) { 454 tmp2 = _table[code] + _offset1; 455 for (i = 0; i < 8; i++) { 456 COPY_4X1_LINE(d_dst + 0, d_dst + tmp2); 457 COPY_4X1_LINE(d_dst + 4, d_dst + tmp2 + 4); 458 d_dst += _d_pitch; 457 const int tmp = _table[code] + _offset1; 458 for (int i = 0; i < 8; i++) { 459 memcpy(d_dst, d_dst + tmp, 8); 460 d_dst += pitch; 459 461 } 460 462 } else if (code == 0xFF) { 461 level2(d_dst); 462 d_dst += 4; 463 level2(d_dst); 464 d_dst += _d_pitch * 4 - 4; 465 level2(d_dst); 466 d_dst += 4; 467 level2(d_dst); 463 level2(d_dst, pitch); 464 level2(d_dst + 4, pitch); 465 d_dst += pitch * 4; 466 level2(d_dst, pitch); 467 level2(d_dst + 4, pitch); 468 468 } else if (code == 0xFE) { 469 byte t = *_d_src++; 470 for (i = 0; i < 8; i++) { 471 FILL_4X1_LINE(d_dst, t); 472 FILL_4X1_LINE(d_dst + 4, t); 473 d_dst += _d_pitch; 469 const byte t = *_d_src++; 470 for (int i = 0; i < 8; i++) { 471 memset(d_dst, t, 8); 472 d_dst += pitch; 474 473 } 475 474 } else if (code == 0xFD) { 476 tmp = *_d_src++;475 const int tmp = *_d_src++; 477 476 byte *tmp_ptr = _tableBig + tmp * 388; 478 477 byte l = tmp_ptr[384]; 479 478 byte val = *_d_src++; … … 490 489 tmp_ptr2++; 491 490 } 492 491 } else if (code == 0xFC) { 493 tmp2 = _offset2; 494 for (i = 0; i < 8; i++) { 495 COPY_4X1_LINE(d_dst + 0, d_dst + tmp2); 496 COPY_4X1_LINE(d_dst + 4, d_dst + tmp2 + 4); 497 d_dst += _d_pitch; 492 const int tmp = _offset2; 493 for (int i = 0; i < 8; i++) { 494 memcpy(d_dst, d_dst + tmp, 8); 495 d_dst += pitch; 498 496 } 499 497 } else { 500 byte t = _paramPtr[code]; 501 for (i = 0; i < 8; i++) { 502 FILL_4X1_LINE(d_dst, t); 503 FILL_4X1_LINE(d_dst + 4, t); 504 d_dst += _d_pitch; 498 const byte t = _paramPtr[code]; 499 for (int i = 0; i < 8; i++) { 500 memset(d_dst, t, 8); 501 d_dst += pitch; 505 502 } 506 503 } 507 504 } … … 512 509 int bw = (width + 7) / 8; 513 510 int bh = (height + 7) / 8; 514 511 int next_line = width * 7; 515 _d_pitch = width;516 512 517 513 do { 518 514 int tmp_bw = bw; 519 515 do { 520 level1(dst );516 level1(dst, width); 521 517 dst += 8; 522 518 } while (--tmp_bw); 523 519 dst += next_line; -
engines/scumm/smush/codec47.h
40 40 int32 _prevSeqNb; 41 41 int _lastTableWidth; 42 42 const byte *_d_src, *_paramPtr; 43 int _d_pitch;44 43 int32 _offset1, _offset2; 45 44 byte *_tableBig; 46 45 byte *_tableSmall; … … 50 49 51 50 void makeTablesInterpolation(int param); 52 51 void makeTables47(int width); 53 void level1(byte *d_dst );54 void level2(byte *d_dst );55 void level3(byte *d_dst );52 void level1(byte *d_dst, const int pitch); 53 void level2(byte *d_dst, const int pitch); 54 void level3(byte *d_dst, const int pitch, uint16 &valA, uint16 &valB); 56 55 void decode2(byte *dst, const byte *src, int width, int height, const byte *param_ptr); 57 56 58 57 public: