| 553 | } |
| 554 | |
| 555 | bool unpack_bc7_mode4_5(uint32_t mode, const void* pBlock_bits, color_rgba* pPixels) |
| 556 | { |
| 557 | const uint32_t ENDPOINTS = 2; |
| 558 | const uint32_t COMPS = 4; |
| 559 | const uint32_t WEIGHT_BITS = 2; |
| 560 | const uint32_t A_WEIGHT_BITS = (mode == 4) ? 3 : 2; |
| 561 | const uint32_t ENDPOINT_BITS = (mode == 4) ? 5 : 7; |
| 562 | const uint32_t A_ENDPOINT_BITS = (mode == 4) ? 6 : 8; |
| 563 | //const uint32_t WEIGHT_VALS = 1 << WEIGHT_BITS; |
| 564 | //const uint32_t A_WEIGHT_VALS = 1 << A_WEIGHT_BITS; |
| 565 | |
| 566 | uint32_t bit_offset = 0; |
| 567 | const uint8_t* pBuf = static_cast<const uint8_t*>(pBlock_bits); |
| 568 | |
| 569 | if (read_bits32(pBuf, bit_offset, mode + 1) != (1U << mode)) return false; |
| 570 | |
| 571 | const uint32_t comp_rot = read_bits32(pBuf, bit_offset, 2); |
| 572 | const uint32_t index_mode = (mode == 4) ? read_bits32(pBuf, bit_offset, 1) : 0; |
| 573 | |
| 574 | color_rgba endpoints[ENDPOINTS]; |
| 575 | for (uint32_t c = 0; c < COMPS; c++) |
| 576 | for (uint32_t e = 0; e < ENDPOINTS; e++) |
| 577 | endpoints[e][c] = (uint8_t)read_bits32(pBuf, bit_offset, (c == 3) ? A_ENDPOINT_BITS : ENDPOINT_BITS); |
| 578 | |
| 579 | const uint32_t weight_bits[2] = { index_mode ? A_WEIGHT_BITS : WEIGHT_BITS, index_mode ? WEIGHT_BITS : A_WEIGHT_BITS }; |
| 580 | |
| 581 | uint32_t weights[16], a_weights[16]; |
| 582 | |
| 583 | for (uint32_t i = 0; i < 16; i++) |
| 584 | (index_mode ? a_weights : weights)[i] = read_bits32(pBuf, bit_offset, weight_bits[index_mode] - ((!i) ? 1 : 0)); |
| 585 | |
| 586 | for (uint32_t i = 0; i < 16; i++) |
| 587 | (index_mode ? weights : a_weights)[i] = read_bits32(pBuf, bit_offset, weight_bits[1 - index_mode] - ((!i) ? 1 : 0)); |
| 588 | |
| 589 | assert(bit_offset == 128); |
| 590 | |
| 591 | for (uint32_t e = 0; e < ENDPOINTS; e++) |
| 592 | for (uint32_t c = 0; c < 4; c++) |
| 593 | endpoints[e][c] = (uint8_t)bc7_dequant(endpoints[e][c], (c == 3) ? A_ENDPOINT_BITS : ENDPOINT_BITS); |
| 594 | |
| 595 | color_rgba block_colors[8]; |
| 596 | for (uint32_t i = 0; i < (1U << weight_bits[0]); i++) |
| 597 | for (uint32_t c = 0; c < 3; c++) |
| 598 | block_colors[i][c] = (uint8_t)bc7_interp(endpoints[0][c], endpoints[1][c], i, weight_bits[0]); |
| 599 | |
| 600 | for (uint32_t i = 0; i < (1U << weight_bits[1]); i++) |
| 601 | block_colors[i][3] = (uint8_t)bc7_interp(endpoints[0][3], endpoints[1][3], i, weight_bits[1]); |
| 602 | |
| 603 | for (uint32_t i = 0; i < 16; i++) |
| 604 | { |
| 605 | pPixels[i] = block_colors[weights[i]]; |
| 606 | pPixels[i].a = block_colors[a_weights[i]].a; |
| 607 | if (comp_rot >= 1) |
| 608 | std::swap(pPixels[i].a, pPixels[i].m_comps[comp_rot - 1]); |
| 609 | } |
| 610 | |
| 611 | return true; |
| 612 | } |
no test coverage detected