Needed for UTX and potentially others outside of DDS
| 2443 | |
| 2444 | // Needed for UTX and potentially others outside of DDS |
| 2445 | ILboolean DecompressDXT1(ILimage *lImage, ILubyte *lCompData) |
| 2446 | { |
| 2447 | ILuint x, y, z, i, j, k, Select; |
| 2448 | ILubyte *Temp; |
| 2449 | Color8888 colours[4], *col; |
| 2450 | ILushort color_0, color_1; |
| 2451 | ILuint bitmask, Offset; |
| 2452 | |
| 2453 | if (!lCompData) |
| 2454 | return IL_FALSE; |
| 2455 | |
| 2456 | Temp = lCompData; |
| 2457 | colours[0].a = 0xFF; |
| 2458 | colours[1].a = 0xFF; |
| 2459 | colours[2].a = 0xFF; |
| 2460 | //colours[3].a = 0xFF; |
| 2461 | for (z = 0; z < lImage->Depth; z++) { |
| 2462 | for (y = 0; y < lImage->Height; y += 4) { |
| 2463 | for (x = 0; x < lImage->Width; x += 4) { |
| 2464 | color_0 = *((ILushort*)Temp); |
| 2465 | UShort(&color_0); |
| 2466 | color_1 = *((ILushort*)(Temp + 2)); |
| 2467 | UShort(&color_1); |
| 2468 | DxtcReadColor(color_0, colours); |
| 2469 | DxtcReadColor(color_1, colours + 1); |
| 2470 | bitmask = ((ILuint*)Temp)[1]; |
| 2471 | UInt(&bitmask); |
| 2472 | Temp += 8; |
| 2473 | |
| 2474 | if (color_0 > color_1) { |
| 2475 | // Four-color block: derive the other two colors. |
| 2476 | // 00 = color_0, 01 = color_1, 10 = color_2, 11 = color_3 |
| 2477 | // These 2-bit codes correspond to the 2-bit fields |
| 2478 | // stored in the 64-bit block. |
| 2479 | colours[2].b = (2 * colours[0].b + colours[1].b + 1) / 3; |
| 2480 | colours[2].g = (2 * colours[0].g + colours[1].g + 1) / 3; |
| 2481 | colours[2].r = (2 * colours[0].r + colours[1].r + 1) / 3; |
| 2482 | //colours[2].a = 0xFF; |
| 2483 | |
| 2484 | colours[3].b = (colours[0].b + 2 * colours[1].b + 1) / 3; |
| 2485 | colours[3].g = (colours[0].g + 2 * colours[1].g + 1) / 3; |
| 2486 | colours[3].r = (colours[0].r + 2 * colours[1].r + 1) / 3; |
| 2487 | colours[3].a = 0xFF; |
| 2488 | } |
| 2489 | else { |
| 2490 | // Three-color block: derive the other color. |
| 2491 | // 00 = color_0, 01 = color_1, 10 = color_2, |
| 2492 | // 11 = transparent. |
| 2493 | // These 2-bit codes correspond to the 2-bit fields |
| 2494 | // stored in the 64-bit block. |
| 2495 | colours[2].b = (colours[0].b + colours[1].b) / 2; |
| 2496 | colours[2].g = (colours[0].g + colours[1].g) / 2; |
| 2497 | colours[2].r = (colours[0].r + colours[1].r) / 2; |
| 2498 | //colours[2].a = 0xFF; |
| 2499 | |
| 2500 | colours[3].b = (colours[0].b + 2 * colours[1].b + 1) / 3; |
| 2501 | colours[3].g = (colours[0].g + 2 * colours[1].g + 1) / 3; |
| 2502 | colours[3].r = (colours[0].r + 2 * colours[1].r + 1) / 3; |
no test coverage detected