| 221 | static inline int interp_half_5_6_amd(int c0, int c1) { assert(c0 < 256 && c1 < 256); return (c0 + c1 + 1) >> 1; } |
| 222 | |
| 223 | bool unpack_bc1_amd(const void *pBlock_bits, color_rgba *pPixels, bool set_alpha) |
| 224 | { |
| 225 | const bc1_block *pBlock = static_cast<const bc1_block *>(pBlock_bits); |
| 226 | |
| 227 | const uint32_t l = pBlock->get_low_color(); |
| 228 | const uint32_t h = pBlock->get_high_color(); |
| 229 | |
| 230 | color_rgba c[4]; |
| 231 | |
| 232 | uint32_t r0, g0, b0, r1, g1, b1; |
| 233 | bc1_block::unpack_color(l, r0, g0, b0); |
| 234 | bc1_block::unpack_color(h, r1, g1, b1); |
| 235 | |
| 236 | c[0].set_noclamp_rgba(r0, g0, b0, 255); |
| 237 | c[1].set_noclamp_rgba(r1, g1, b1, 255); |
| 238 | |
| 239 | bool used_punchthrough = false; |
| 240 | |
| 241 | if (l > h) |
| 242 | { |
| 243 | c[2].set_noclamp_rgba(interp_5_6_amd(r0, r1), interp_5_6_amd(g0, g1), interp_5_6_amd(b0, b1), 255); |
| 244 | c[3].set_noclamp_rgba(interp_5_6_amd(r1, r0), interp_5_6_amd(g1, g0), interp_5_6_amd(b1, b0), 255); |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | c[2].set_noclamp_rgba(interp_half_5_6_amd(r0, r1), interp_half_5_6_amd(g0, g1), interp_half_5_6_amd(b0, b1), 255); |
| 249 | c[3].set_noclamp_rgba(0, 0, 0, 0); |
| 250 | used_punchthrough = true; |
| 251 | } |
| 252 | |
| 253 | if (set_alpha) |
| 254 | { |
| 255 | for (uint32_t y = 0; y < 4; y++, pPixels += 4) |
| 256 | { |
| 257 | pPixels[0] = c[pBlock->get_selector(0, y)]; |
| 258 | pPixels[1] = c[pBlock->get_selector(1, y)]; |
| 259 | pPixels[2] = c[pBlock->get_selector(2, y)]; |
| 260 | pPixels[3] = c[pBlock->get_selector(3, y)]; |
| 261 | } |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | for (uint32_t y = 0; y < 4; y++, pPixels += 4) |
| 266 | { |
| 267 | pPixels[0].set_rgb(c[pBlock->get_selector(0, y)]); |
| 268 | pPixels[1].set_rgb(c[pBlock->get_selector(1, y)]); |
| 269 | pPixels[2].set_rgb(c[pBlock->get_selector(2, y)]); |
| 270 | pPixels[3].set_rgb(c[pBlock->get_selector(3, y)]); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | return used_punchthrough; |
| 275 | } |
| 276 | |
| 277 | struct bc4_block |
| 278 | { |
no test coverage detected