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

Function unpack_pvrtc2

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

PVRTC2 is currently limited to only what our transcoder outputs (non-interpolated, hard_flag=1 modulation=0). In this mode, PVRTC2 looks much like BC1/ATC.

Source from the content-addressed store, hash-verified

958
959 // PVRTC2 is currently limited to only what our transcoder outputs (non-interpolated, hard_flag=1 modulation=0). In this mode, PVRTC2 looks much like BC1/ATC.
960 bool unpack_pvrtc2(const void *p, color_rgba *pPixels)
961 {
962 const pvrtc2_block* pBlock = static_cast<const pvrtc2_block*>(p);
963
964 if ((!pBlock->m_opaque_color_data.m_hard_flag) || (pBlock->m_opaque_color_data.m_mod_flag))
965 {
966 // This mode isn't supported by the transcoder, so we aren't bothering with it here.
967 return false;
968 }
969
970 color_rgba colors[4];
971
972 if (pBlock->m_opaque_color_data.m_opaque_flag)
973 {
974 // colora=554
975 color_rgba color_a(pBlock->m_opaque_color_data.m_red_a, pBlock->m_opaque_color_data.m_green_a, (pBlock->m_opaque_color_data.m_blue_a << 1) | (pBlock->m_opaque_color_data.m_blue_a >> 3), 255);
976
977 // colora=555
978 color_rgba color_b(pBlock->m_opaque_color_data.m_red_b, pBlock->m_opaque_color_data.m_green_b, pBlock->m_opaque_color_data.m_blue_b, 255);
979
980 colors[0] = convert_rgb_555_to_888(color_a);
981 colors[3] = convert_rgb_555_to_888(color_b);
982
983 colors[1].set((colors[0].r * 5 + colors[3].r * 3) / 8, (colors[0].g * 5 + colors[3].g * 3) / 8, (colors[0].b * 5 + colors[3].b * 3) / 8, 255);
984 colors[2].set((colors[0].r * 3 + colors[3].r * 5) / 8, (colors[0].g * 3 + colors[3].g * 5) / 8, (colors[0].b * 3 + colors[3].b * 5) / 8, 255);
985 }
986 else
987 {
988 // colora=4433
989 color_rgba color_a(
990 (pBlock->m_trans_color_data.m_red_a << 1) | (pBlock->m_trans_color_data.m_red_a >> 3),
991 (pBlock->m_trans_color_data.m_green_a << 1) | (pBlock->m_trans_color_data.m_green_a >> 3),
992 (pBlock->m_trans_color_data.m_blue_a << 2) | (pBlock->m_trans_color_data.m_blue_a >> 1),
993 pBlock->m_trans_color_data.m_alpha_a << 1);
994
995 //colorb=4443
996 color_rgba color_b(
997 (pBlock->m_trans_color_data.m_red_b << 1) | (pBlock->m_trans_color_data.m_red_b >> 3),
998 (pBlock->m_trans_color_data.m_green_b << 1) | (pBlock->m_trans_color_data.m_green_b >> 3),
999 (pBlock->m_trans_color_data.m_blue_b << 1) | (pBlock->m_trans_color_data.m_blue_b >> 3),
1000 (pBlock->m_trans_color_data.m_alpha_b << 1) | 1);
1001
1002 colors[0] = convert_rgba_5554_to_8888(color_a);
1003 colors[3] = convert_rgba_5554_to_8888(color_b);
1004 }
1005
1006 colors[1].set((colors[0].r * 5 + colors[3].r * 3) / 8, (colors[0].g * 5 + colors[3].g * 3) / 8, (colors[0].b * 5 + colors[3].b * 3) / 8, (colors[0].a * 5 + colors[3].a * 3) / 8);
1007 colors[2].set((colors[0].r * 3 + colors[3].r * 5) / 8, (colors[0].g * 3 + colors[3].g * 5) / 8, (colors[0].b * 3 + colors[3].b * 5) / 8, (colors[0].a * 3 + colors[3].a * 5) / 8);
1008
1009 for (uint32_t i = 0; i < 16; i++)
1010 {
1011 const uint32_t sel = (pBlock->m_modulation[i >> 2] >> ((i & 3) * 2)) & 3;
1012 pPixels[i] = colors[sel];
1013 }
1014
1015 return true;
1016 }
1017

Callers 1

unpack_blockFunction · 0.85

Calls 3

convert_rgb_555_to_888Function · 0.85
setMethod · 0.45

Tested by

no test coverage detected