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

Function unpack_bc1

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

Returns true if the block uses 3 color punchthrough alpha mode.

Source from the content-addressed store, hash-verified

83
84 // Returns true if the block uses 3 color punchthrough alpha mode.
85 bool unpack_bc1(const void *pBlock_bits, color_rgba *pPixels, bool set_alpha)
86 {
87 static_assert(sizeof(bc1_block) == 8, "sizeof(bc1_block) == 8");
88
89 const bc1_block *pBlock = static_cast<const bc1_block *>(pBlock_bits);
90
91 const uint32_t l = pBlock->get_low_color();
92 const uint32_t h = pBlock->get_high_color();
93
94 color_rgba c[4];
95
96 uint32_t r0, g0, b0, r1, g1, b1;
97 bc1_block::unpack_color(l, r0, g0, b0);
98 bc1_block::unpack_color(h, r1, g1, b1);
99
100 c[0].set_noclamp_rgba(r0, g0, b0, 255);
101 c[1].set_noclamp_rgba(r1, g1, b1, 255);
102
103 bool used_punchthrough = false;
104
105 if (l > h)
106 {
107 c[2].set_noclamp_rgba((r0 * 2 + r1) / 3, (g0 * 2 + g1) / 3, (b0 * 2 + b1) / 3, 255);
108 c[3].set_noclamp_rgba((r1 * 2 + r0) / 3, (g1 * 2 + g0) / 3, (b1 * 2 + b0) / 3, 255);
109 }
110 else
111 {
112 c[2].set_noclamp_rgba((r0 + r1) / 2, (g0 + g1) / 2, (b0 + b1) / 2, 255);
113 c[3].set_noclamp_rgba(0, 0, 0, 0);
114 used_punchthrough = true;
115 }
116
117 if (set_alpha)
118 {
119 for (uint32_t y = 0; y < 4; y++, pPixels += 4)
120 {
121 pPixels[0] = c[pBlock->get_selector(0, y)];
122 pPixels[1] = c[pBlock->get_selector(1, y)];
123 pPixels[2] = c[pBlock->get_selector(2, y)];
124 pPixels[3] = c[pBlock->get_selector(3, y)];
125 }
126 }
127 else
128 {
129 for (uint32_t y = 0; y < 4; y++, pPixels += 4)
130 {
131 pPixels[0].set_rgb(c[pBlock->get_selector(0, y)]);
132 pPixels[1].set_rgb(c[pBlock->get_selector(1, y)]);
133 pPixels[2].set_rgb(c[pBlock->get_selector(2, y)]);
134 pPixels[3].set_rgb(c[pBlock->get_selector(3, y)]);
135 }
136 }
137
138 return used_punchthrough;
139 }
140
141 bool unpack_bc1_nv(const void *pBlock_bits, color_rgba *pPixels, bool set_alpha)
142 {

Callers 2

unpack_bc3Function · 0.85
unpack_blockFunction · 0.85

Calls 4

set_noclamp_rgbaMethod · 0.80
get_low_colorMethod · 0.45
get_high_colorMethod · 0.45
get_selectorMethod · 0.45

Tested by

no test coverage detected