MCPcopy Create free account
hub / github.com/defold/defold / unpack_bc7_mode1_3_7

Function unpack_bc7_mode1_3_7

engine/dlib/src/basis/encoder/basisu_gpu_texture.cpp:503–553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

501 }
502
503 bool unpack_bc7_mode1_3_7(uint32_t mode, const void* pBlock_bits, color_rgba* pPixels)
504 {
505 //const uint32_t SUBSETS = 2;
506 const uint32_t ENDPOINTS = 4;
507 const uint32_t COMPS = (mode == 7) ? 4 : 3;
508 const uint32_t WEIGHT_BITS = (mode == 1) ? 3 : 2;
509 const uint32_t ENDPOINT_BITS = (mode == 7) ? 5 : ((mode == 1) ? 6 : 7);
510 const uint32_t PBITS = (mode == 1) ? 2 : 4;
511 const uint32_t SHARED_PBITS = (mode == 1) ? true : false;
512 const uint32_t WEIGHT_VALS = 1 << WEIGHT_BITS;
513
514 uint32_t bit_offset = 0;
515 const uint8_t* pBuf = static_cast<const uint8_t*>(pBlock_bits);
516
517 if (read_bits32(pBuf, bit_offset, mode + 1) != (1U << mode)) return false;
518
519 const uint32_t part = read_bits32(pBuf, bit_offset, 6);
520
521 color_rgba endpoints[ENDPOINTS];
522 for (uint32_t c = 0; c < COMPS; c++)
523 for (uint32_t e = 0; e < ENDPOINTS; e++)
524 endpoints[e][c] = (uint8_t)read_bits32(pBuf, bit_offset, ENDPOINT_BITS);
525
526 uint32_t pbits[4];
527 for (uint32_t p = 0; p < PBITS; p++)
528 pbits[p] = read_bits32(pBuf, bit_offset, 1);
529
530 uint32_t weights[16];
531 for (uint32_t i = 0; i < 16; i++)
532 weights[i] = read_bits32(pBuf, bit_offset, ((!i) || (i == basist::g_bc7_table_anchor_index_second_subset[part])) ? (WEIGHT_BITS - 1) : WEIGHT_BITS);
533
534 assert(bit_offset == 128);
535
536 for (uint32_t e = 0; e < ENDPOINTS; e++)
537 for (uint32_t c = 0; c < 4; c++)
538 endpoints[e][c] = (uint8_t)((c == ((mode == 7U) ? 4U : 3U)) ? 255 : bc7_dequant(endpoints[e][c], pbits[SHARED_PBITS ? (e >> 1) : e], ENDPOINT_BITS));
539
540 color_rgba block_colors[2][8];
541 for (uint32_t s = 0; s < 2; s++)
542 for (uint32_t i = 0; i < WEIGHT_VALS; i++)
543 {
544 for (uint32_t c = 0; c < COMPS; c++)
545 block_colors[s][i][c] = (uint8_t)bc7_interp(endpoints[s * 2 + 0][c], endpoints[s * 2 + 1][c], i, WEIGHT_BITS);
546 block_colors[s][i][3] = (COMPS == 3) ? 255 : block_colors[s][i][3];
547 }
548
549 for (uint32_t i = 0; i < 16; i++)
550 pPixels[i] = block_colors[basist::g_bc7_partition2[part * 16 + i]][weights[i]];
551
552 return true;
553 }
554
555 bool unpack_bc7_mode4_5(uint32_t mode, const void* pBlock_bits, color_rgba* pPixels)
556 {

Callers 1

unpack_bc7Function · 0.85

Calls 4

read_bits32Function · 0.85
bc7_dequantFunction · 0.85
bc7_interpFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected