| 1429 | } |
| 1430 | |
| 1431 | static void decodeBlockDxt1(uint8_t _dst[16*4], const uint8_t _src[8]) |
| 1432 | { |
| 1433 | if (!BX_ENABLED(BIMG_DECODE_BC1 || BIMG_DECODE_BC2 || BIMG_DECODE_BC3) ) |
| 1434 | { |
| 1435 | return; |
| 1436 | } |
| 1437 | |
| 1438 | uint8_t colors[4*4]; |
| 1439 | |
| 1440 | uint32_t c0 = _src[0] | (_src[1] << 8); |
| 1441 | colors[0] = bitRangeConvert( (c0>> 0)&0x1f, 5, 8); |
| 1442 | colors[1] = bitRangeConvert( (c0>> 5)&0x3f, 6, 8); |
| 1443 | colors[2] = bitRangeConvert( (c0>>11)&0x1f, 5, 8); |
| 1444 | colors[3] = 255; |
| 1445 | |
| 1446 | uint32_t c1 = _src[2] | (_src[3] << 8); |
| 1447 | colors[4] = bitRangeConvert( (c1>> 0)&0x1f, 5, 8); |
| 1448 | colors[5] = bitRangeConvert( (c1>> 5)&0x3f, 6, 8); |
| 1449 | colors[6] = bitRangeConvert( (c1>>11)&0x1f, 5, 8); |
| 1450 | colors[7] = 255; |
| 1451 | |
| 1452 | if (c0 > c1) |
| 1453 | { |
| 1454 | colors[ 8] = (2*colors[0] + colors[4]) / 3; |
| 1455 | colors[ 9] = (2*colors[1] + colors[5]) / 3; |
| 1456 | colors[10] = (2*colors[2] + colors[6]) / 3; |
| 1457 | colors[11] = 255; |
| 1458 | |
| 1459 | colors[12] = (colors[0] + 2*colors[4]) / 3; |
| 1460 | colors[13] = (colors[1] + 2*colors[5]) / 3; |
| 1461 | colors[14] = (colors[2] + 2*colors[6]) / 3; |
| 1462 | colors[15] = 255; |
| 1463 | } |
| 1464 | else |
| 1465 | { |
| 1466 | colors[ 8] = (colors[0] + colors[4]) / 2; |
| 1467 | colors[ 9] = (colors[1] + colors[5]) / 2; |
| 1468 | colors[10] = (colors[2] + colors[6]) / 2; |
| 1469 | colors[11] = 255; |
| 1470 | |
| 1471 | colors[12] = 0; |
| 1472 | colors[13] = 0; |
| 1473 | colors[14] = 0; |
| 1474 | colors[15] = 0; |
| 1475 | } |
| 1476 | |
| 1477 | for (uint32_t ii = 0, next = 8*4; ii < 16*4; ii += 4, next += 2) |
| 1478 | { |
| 1479 | int idx = ( (_src[next>>3] >> (next & 7) ) & 3) * 4; |
| 1480 | _dst[ii+0] = colors[idx+0]; |
| 1481 | _dst[ii+1] = colors[idx+1]; |
| 1482 | _dst[ii+2] = colors[idx+2]; |
| 1483 | _dst[ii+3] = colors[idx+3]; |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | static void decodeBlockDxt23A(uint8_t _dst[16*4], const uint8_t _src[8]) |
| 1488 | { |
no test coverage detected