| 719 | } |
| 720 | |
| 721 | static bool LoadATI2( QDataStream & s, const DDSHeader & header, QImage & img ) |
| 722 | { |
| 723 | const uint w = header.width; |
| 724 | const uint h = header.height; |
| 725 | |
| 726 | BlockDXTAlphaLinear xblock; |
| 727 | BlockDXTAlphaLinear yblock; |
| 728 | QRgb * scanline[4]; |
| 729 | |
| 730 | for( uint y = 0; y < h; y += 4 ) { |
| 731 | for( uint j = 0; j < 4; j++ ) { |
| 732 | scanline[j] = (QRgb *) img.scanLine( y + j ); |
| 733 | } |
| 734 | for( uint x = 0; x < w; x += 4 ) { |
| 735 | |
| 736 | // Read 128bit color block. |
| 737 | s >> xblock; |
| 738 | s >> yblock; |
| 739 | |
| 740 | // Decode color block. |
| 741 | uchar xblock_array[8]; |
| 742 | xblock.GetAlphas(xblock_array); |
| 743 | |
| 744 | uchar xbit_array[16]; |
| 745 | xblock.GetBits(xbit_array); |
| 746 | |
| 747 | uchar yblock_array[8]; |
| 748 | yblock.GetAlphas(yblock_array); |
| 749 | |
| 750 | uchar ybit_array[16]; |
| 751 | yblock.GetBits(ybit_array); |
| 752 | |
| 753 | // Write color block. |
| 754 | for( uint j = 0; j < 4; j++ ) { |
| 755 | for( uint i = 0; i < 4; i++ ) { |
| 756 | if( img.valid( x+i, y+j ) ) { |
| 757 | const uchar nx = xblock_array[xbit_array[j*4+i]]; |
| 758 | const uchar ny = yblock_array[ybit_array[j*4+i]]; |
| 759 | |
| 760 | const float fx = float(nx) / 127.5f - 1.0f; |
| 761 | const float fy = float(ny) / 127.5f - 1.0f; |
| 762 | const float fz = sqrtf(1.0f - fx*fx - fy*fy); |
| 763 | const uchar nz = uchar((fz + 1.0f) * 127.5f); |
| 764 | |
| 765 | scanline[j][x+i] = qRgb(nx, ny, nz); |
| 766 | } |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | return true; |
| 773 | } |
| 774 | |
| 775 | |
| 776 | |