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

Function unpack_fxt1

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

We only support CC_MIXED non-alpha blocks here because that's the only mode the transcoder uses at the moment.

Source from the content-addressed store, hash-verified

835
836 // We only support CC_MIXED non-alpha blocks here because that's the only mode the transcoder uses at the moment.
837 bool unpack_fxt1(const void *p, color_rgba *pPixels)
838 {
839 const fxt1_block* pBlock = static_cast<const fxt1_block*>(p);
840
841 if (pBlock->m_hi.m_mode == 0)
842 return false;
843 if (pBlock->m_hi.m_alpha == 1)
844 return false;
845
846 color_rgba colors[4];
847
848 colors[0].r = pBlock->m_hi.m_r0;
849 colors[0].g = (uint8_t)((pBlock->m_hi.m_g0 << 1) | ((pBlock->m_lo.m_t00 >> 1) ^ (pBlock->m_hi.m_glsb & 1)));
850 colors[0].b = pBlock->m_hi.m_b0;
851 colors[0].a = 255;
852
853 colors[1].r = pBlock->m_hi.m_r1;
854 colors[1].g = (uint8_t)((pBlock->m_hi.m_g1 << 1) | (pBlock->m_hi.m_glsb & 1));
855 colors[1].b = pBlock->m_hi.m_b1;
856 colors[1].a = 255;
857
858 colors[2].r = pBlock->m_hi.m_r2;
859 colors[2].g = (uint8_t)((pBlock->m_hi.m_g2 << 1) | ((pBlock->m_lo.m_t16 >> 1) ^ (pBlock->m_hi.m_glsb >> 1)));
860 colors[2].b = pBlock->m_hi.m_b2;
861 colors[2].a = 255;
862
863 colors[3].r = pBlock->m_hi.m_r3;
864 colors[3].g = (uint8_t)((pBlock->m_hi.m_g3 << 1) | (pBlock->m_hi.m_glsb >> 1));
865 colors[3].b = pBlock->m_hi.m_b3;
866 colors[3].a = 255;
867
868 for (uint32_t i = 0; i < 4; i++)
869 colors[i] = expand_565(colors[i]);
870
871 color_rgba block0_colors[4];
872 block0_colors[0] = colors[0];
873 block0_colors[1] = color_rgba((colors[0].r * 2 + colors[1].r + 1) / 3, (colors[0].g * 2 + colors[1].g + 1) / 3, (colors[0].b * 2 + colors[1].b + 1) / 3, 255);
874 block0_colors[2] = color_rgba((colors[1].r * 2 + colors[0].r + 1) / 3, (colors[1].g * 2 + colors[0].g + 1) / 3, (colors[1].b * 2 + colors[0].b + 1) / 3, 255);
875 block0_colors[3] = colors[1];
876
877 for (uint32_t i = 0; i < 16; i++)
878 {
879 const uint32_t sel = (pBlock->m_sels[i >> 2] >> ((i & 3) * 2)) & 3;
880
881 const uint32_t x = i & 3;
882 const uint32_t y = i >> 2;
883 pPixels[x + y * 8] = block0_colors[sel];
884 }
885
886 color_rgba block1_colors[4];
887 block1_colors[0] = colors[2];
888 block1_colors[1] = color_rgba((colors[2].r * 2 + colors[3].r + 1) / 3, (colors[2].g * 2 + colors[3].g + 1) / 3, (colors[2].b * 2 + colors[3].b + 1) / 3, 255);
889 block1_colors[2] = color_rgba((colors[3].r * 2 + colors[2].r + 1) / 3, (colors[3].g * 2 + colors[2].g + 1) / 3, (colors[3].b * 2 + colors[2].b + 1) / 3, 255);
890 block1_colors[3] = colors[3];
891
892 for (uint32_t i = 0; i < 16; i++)
893 {
894 const uint32_t sel = (pBlock->m_sels[4 + (i >> 2)] >> ((i & 3) * 2)) & 3;

Callers 1

unpack_blockFunction · 0.85

Calls 2

expand_565Function · 0.85
color_rgbaClass · 0.85

Tested by

no test coverage detected