| 520 | } |
| 521 | |
| 522 | static bool LoadDXT1( QDataStream & s, const DDSHeader & header, QImage & img ) |
| 523 | { |
| 524 | const uint w = header.width; |
| 525 | const uint h = header.height; |
| 526 | |
| 527 | BlockDXT block; |
| 528 | QRgb * scanline[4]; |
| 529 | |
| 530 | for( uint y = 0; y < h; y += 4 ) { |
| 531 | for( uint j = 0; j < 4; j++ ) { |
| 532 | scanline[j] = (QRgb *) img.scanLine( y + j ); |
| 533 | } |
| 534 | for( uint x = 0; x < w; x += 4 ) { |
| 535 | |
| 536 | // Read 64bit color block. |
| 537 | s >> block; |
| 538 | |
| 539 | // Decode color block. |
| 540 | Color8888 color_array[4]; |
| 541 | block.GetColors(color_array); |
| 542 | |
| 543 | // bit masks = 00000011, 00001100, 00110000, 11000000 |
| 544 | const uint masks[4] = { 3, 3<<2, 3<<4, 3<<6 }; |
| 545 | const int shift[4] = { 0, 2, 4, 6 }; |
| 546 | |
| 547 | // Write color block. |
| 548 | for( uint j = 0; j < 4; j++ ) { |
| 549 | for( uint i = 0; i < 4; i++ ) { |
| 550 | if( img.valid( x+i, y+j ) ) { |
| 551 | uint idx = (block.row[j] & masks[i]) >> shift[i]; |
| 552 | scanline[j][x+i] = qRgba(color_array[idx].r, color_array[idx].g, color_array[idx].b, color_array[idx].a); |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | return true; |
| 559 | } |
| 560 | |
| 561 | static bool LoadDXT3( QDataStream & s, const DDSHeader & header, QImage & img ) |
| 562 | { |