| 559 | } |
| 560 | |
| 561 | static bool LoadDXT3( QDataStream & s, const DDSHeader & header, QImage & img ) |
| 562 | { |
| 563 | const uint w = header.width; |
| 564 | const uint h = header.height; |
| 565 | |
| 566 | BlockDXT block; |
| 567 | BlockDXTAlphaExplicit alpha; |
| 568 | QRgb * scanline[4]; |
| 569 | |
| 570 | for( uint y = 0; y < h; y += 4 ) { |
| 571 | for( uint j = 0; j < 4; j++ ) { |
| 572 | scanline[j] = (QRgb *) img.scanLine( y + j ); |
| 573 | } |
| 574 | for( uint x = 0; x < w; x += 4 ) { |
| 575 | |
| 576 | // Read 128bit color block. |
| 577 | s >> alpha; |
| 578 | s >> block; |
| 579 | |
| 580 | // Decode color block. |
| 581 | Color8888 color_array[4]; |
| 582 | block.GetColors(color_array); |
| 583 | |
| 584 | // bit masks = 00000011, 00001100, 00110000, 11000000 |
| 585 | const uint masks[4] = { 3, 3<<2, 3<<4, 3<<6 }; |
| 586 | const int shift[4] = { 0, 2, 4, 6 }; |
| 587 | |
| 588 | // Write color block. |
| 589 | for( uint j = 0; j < 4; j++ ) { |
| 590 | ushort a = alpha.row[j]; |
| 591 | for( uint i = 0; i < 4; i++ ) { |
| 592 | if( img.valid( x+i, y+j ) ) { |
| 593 | uint idx = (block.row[j] & masks[i]) >> shift[i]; |
| 594 | color_array[idx].a = a & 0x0f; |
| 595 | color_array[idx].a = color_array[idx].a | (color_array[idx].a << 4); |
| 596 | scanline[j][x+i] = qRgba(color_array[idx].r, color_array[idx].g, color_array[idx].b, color_array[idx].a); |
| 597 | } |
| 598 | a >>= 4; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | return true; |
| 604 | } |
| 605 | |
| 606 | static bool LoadDXT2( QDataStream & s, const DDSHeader & header, QImage & img ) |
| 607 | { |