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

Function unpack_bc7_mode0_2

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

Source from the content-addressed store, hash-verified

450 }
451
452 bool unpack_bc7_mode0_2(uint32_t mode, const void* pBlock_bits, color_rgba* pPixels)
453 {
454 //const uint32_t SUBSETS = 3;
455 const uint32_t ENDPOINTS = 6;
456 const uint32_t COMPS = 3;
457 const uint32_t WEIGHT_BITS = (mode == 0) ? 3 : 2;
458 const uint32_t ENDPOINT_BITS = (mode == 0) ? 4 : 5;
459 const uint32_t PBITS = (mode == 0) ? 6 : 0;
460 const uint32_t WEIGHT_VALS = 1 << WEIGHT_BITS;
461
462 uint32_t bit_offset = 0;
463 const uint8_t* pBuf = static_cast<const uint8_t*>(pBlock_bits);
464
465 if (read_bits32(pBuf, bit_offset, mode + 1) != (1U << mode)) return false;
466
467 const uint32_t part = read_bits32(pBuf, bit_offset, (mode == 0) ? 4 : 6);
468
469 color_rgba endpoints[ENDPOINTS];
470 for (uint32_t c = 0; c < COMPS; c++)
471 for (uint32_t e = 0; e < ENDPOINTS; e++)
472 endpoints[e][c] = (uint8_t)read_bits32(pBuf, bit_offset, ENDPOINT_BITS);
473
474 uint32_t pbits[6];
475 for (uint32_t p = 0; p < PBITS; p++)
476 pbits[p] = read_bits32(pBuf, bit_offset, 1);
477
478 uint32_t weights[16];
479 for (uint32_t i = 0; i < 16; i++)
480 weights[i] = read_bits32(pBuf, bit_offset, ((!i) || (i == basist::g_bc7_table_anchor_index_third_subset_1[part]) || (i == basist::g_bc7_table_anchor_index_third_subset_2[part])) ? (WEIGHT_BITS - 1) : WEIGHT_BITS);
481
482 assert(bit_offset == 128);
483
484 for (uint32_t e = 0; e < ENDPOINTS; e++)
485 for (uint32_t c = 0; c < 4; c++)
486 endpoints[e][c] = (uint8_t)((c == 3) ? 255 : (PBITS ? bc7_dequant(endpoints[e][c], pbits[e], ENDPOINT_BITS) : bc7_dequant(endpoints[e][c], ENDPOINT_BITS)));
487
488 color_rgba block_colors[3][8];
489 for (uint32_t s = 0; s < 3; s++)
490 for (uint32_t i = 0; i < WEIGHT_VALS; i++)
491 {
492 for (uint32_t c = 0; c < 3; c++)
493 block_colors[s][i][c] = (uint8_t)bc7_interp(endpoints[s * 2 + 0][c], endpoints[s * 2 + 1][c], i, WEIGHT_BITS);
494 block_colors[s][i][3] = 255;
495 }
496
497 for (uint32_t i = 0; i < 16; i++)
498 pPixels[i] = block_colors[basist::g_bc7_partition3[part * 16 + i]][weights[i]];
499
500 return true;
501 }
502
503 bool unpack_bc7_mode1_3_7(uint32_t mode, const void* pBlock_bits, color_rgba* pPixels)
504 {

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