ATC isn't officially documented, so I'm assuming these references: http://www.guildsoftware.com/papers/2012.Converting.DXTC.to.ATC.pdf https://github.com/Triang3l/S3TConv/blob/master/s3tconv_atitc.c The paper incorrectly says the ATC lerp factors are 1/3 and 2/3, but they are actually 3/8 and 5/8.
| 378 | // https://github.com/Triang3l/S3TConv/blob/master/s3tconv_atitc.c |
| 379 | // The paper incorrectly says the ATC lerp factors are 1/3 and 2/3, but they are actually 3/8 and 5/8. |
| 380 | void unpack_atc(const void* pBlock_bits, color_rgba* pPixels) |
| 381 | { |
| 382 | const uint8_t* pBytes = static_cast<const uint8_t*>(pBlock_bits); |
| 383 | |
| 384 | const uint16_t color0 = pBytes[0] | (pBytes[1] << 8U); |
| 385 | const uint16_t color1 = pBytes[2] | (pBytes[3] << 8U); |
| 386 | uint32_t sels = pBytes[4] | (pBytes[5] << 8U) | (pBytes[6] << 16U) | (pBytes[7] << 24U); |
| 387 | |
| 388 | const bool mode = (color0 & 0x8000) != 0; |
| 389 | |
| 390 | color_rgba c[4]; |
| 391 | |
| 392 | c[0].set((color0 >> 10) & 31, (color0 >> 5) & 31, color0 & 31, 255); |
| 393 | c[0].r = (c[0].r << 3) | (c[0].r >> 2); |
| 394 | c[0].g = (c[0].g << 3) | (c[0].g >> 2); |
| 395 | c[0].b = (c[0].b << 3) | (c[0].b >> 2); |
| 396 | |
| 397 | c[3].set((color1 >> 11) & 31, (color1 >> 5) & 63, color1 & 31, 255); |
| 398 | c[3].r = (c[3].r << 3) | (c[3].r >> 2); |
| 399 | c[3].g = (c[3].g << 2) | (c[3].g >> 4); |
| 400 | c[3].b = (c[3].b << 3) | (c[3].b >> 2); |
| 401 | |
| 402 | if (mode) |
| 403 | { |
| 404 | c[1].set(basisu::maximum(0, c[0].r - (c[3].r >> 2)), basisu::maximum(0, c[0].g - (c[3].g >> 2)), basisu::maximum(0, c[0].b - (c[3].b >> 2)), 255); |
| 405 | c[2] = c[0]; |
| 406 | c[0].set(0, 0, 0, 255); |
| 407 | } |
| 408 | else |
| 409 | { |
| 410 | c[1].r = (c[0].r * 5 + c[3].r * 3) >> 3; |
| 411 | c[1].g = (c[0].g * 5 + c[3].g * 3) >> 3; |
| 412 | c[1].b = (c[0].b * 5 + c[3].b * 3) >> 3; |
| 413 | |
| 414 | c[2].r = (c[0].r * 3 + c[3].r * 5) >> 3; |
| 415 | c[2].g = (c[0].g * 3 + c[3].g * 5) >> 3; |
| 416 | c[2].b = (c[0].b * 3 + c[3].b * 5) >> 3; |
| 417 | } |
| 418 | |
| 419 | for (uint32_t i = 0; i < 16; i++) |
| 420 | { |
| 421 | const uint32_t s = sels & 3; |
| 422 | |
| 423 | pPixels[i] = c[s]; |
| 424 | |
| 425 | sels >>= 2; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | // BC7 mode 0-7 decompression. |
| 430 | // Instead of one monster routine to unpack all the BC7 modes, we're lumping the 3 subset, 2 subset, 1 subset, and dual plane modes together into simple shared routines. |
no test coverage detected