| 1033 | |
| 1034 | |
| 1035 | ILboolean DecompressDXT3(ILimage *lImage, ILubyte *lCompData) |
| 1036 | { |
| 1037 | ILuint x, y, z, i, j, k, Select; |
| 1038 | ILubyte *Temp; |
| 1039 | //Color565 *color_0, *color_1; |
| 1040 | Color8888 colours[4], *col; |
| 1041 | ILuint bitmask, Offset; |
| 1042 | ILushort word; |
| 1043 | ILubyte *alpha; |
| 1044 | |
| 1045 | if (!lCompData) |
| 1046 | return IL_FALSE; |
| 1047 | |
| 1048 | Temp = lCompData; |
| 1049 | for (z = 0; z < lImage->Depth; z++) { |
| 1050 | for (y = 0; y < lImage->Height; y += 4) { |
| 1051 | for (x = 0; x < lImage->Width; x += 4) { |
| 1052 | alpha = Temp; |
| 1053 | Temp += 8; |
| 1054 | DxtcReadColors(Temp, colours); |
| 1055 | bitmask = ((ILuint*)Temp)[1]; |
| 1056 | UInt(&bitmask); |
| 1057 | Temp += 8; |
| 1058 | |
| 1059 | // Four-color block: derive the other two colors. |
| 1060 | // 00 = color_0, 01 = color_1, 10 = color_2, 11 = color_3 |
| 1061 | // These 2-bit codes correspond to the 2-bit fields |
| 1062 | // stored in the 64-bit block. |
| 1063 | colours[2].b = (2 * colours[0].b + colours[1].b + 1) / 3; |
| 1064 | colours[2].g = (2 * colours[0].g + colours[1].g + 1) / 3; |
| 1065 | colours[2].r = (2 * colours[0].r + colours[1].r + 1) / 3; |
| 1066 | //colours[2].a = 0xFF; |
| 1067 | |
| 1068 | colours[3].b = (colours[0].b + 2 * colours[1].b + 1) / 3; |
| 1069 | colours[3].g = (colours[0].g + 2 * colours[1].g + 1) / 3; |
| 1070 | colours[3].r = (colours[0].r + 2 * colours[1].r + 1) / 3; |
| 1071 | //colours[3].a = 0xFF; |
| 1072 | |
| 1073 | k = 0; |
| 1074 | for (j = 0; j < 4; j++) { |
| 1075 | for (i = 0; i < 4; i++, k++) { |
| 1076 | Select = (bitmask & (0x03 << k*2)) >> k*2; |
| 1077 | col = &colours[Select]; |
| 1078 | |
| 1079 | if (((x + i) < lImage->Width) && ((y + j) < lImage->Height)) { |
| 1080 | Offset = z * lImage->SizeOfPlane + (y + j) * lImage->Bps + (x + i) * lImage->Bpp; |
| 1081 | lImage->Data[Offset + 0] = col->r; |
| 1082 | lImage->Data[Offset + 1] = col->g; |
| 1083 | lImage->Data[Offset + 2] = col->b; |
| 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | for (j = 0; j < 4; j++) { |
| 1089 | word = alpha[2*j] + 256*alpha[2*j+1]; |
| 1090 | for (i = 0; i < 4; i++) { |
| 1091 | if (((x + i) < lImage->Width) && ((y + j) < lImage->Height)) { |
| 1092 | Offset = z * lImage->SizeOfPlane + (y + j) * lImage->Bps + (x + i) * lImage->Bpp + 3; |
no test coverage detected