MCPcopy Create free account
hub / github.com/crownengine/crown / decodeBlockATC

Function decodeBlockATC

3rdparty/bimg/src/image.cpp:2553–2610  ·  view source on GitHub ↗

ATC

Source from the content-addressed store, hash-verified

2551 // ATC
2552 //
2553 static void decodeBlockATC(uint8_t _dst[16*4], const uint8_t _src[8])
2554 {
2555 if (!BX_ENABLED(BIMG_DECODE_ATC) )
2556 {
2557 return;
2558 }
2559
2560 uint8_t colors[4*4];
2561
2562 uint32_t c0 = _src[0] | (_src[1] << 8);
2563 uint32_t c1 = _src[2] | (_src[3] << 8);
2564
2565 if (0 == (c0 & 0x8000) )
2566 {
2567 colors[ 0] = bitRangeConvert( (c0>> 0)&0x1f, 5, 8);
2568 colors[ 1] = bitRangeConvert( (c0>> 5)&0x1f, 5, 8);
2569 colors[ 2] = bitRangeConvert( (c0>>10)&0x1f, 5, 8);
2570
2571 colors[12] = bitRangeConvert( (c1>> 0)&0x1f, 5, 8);
2572 colors[13] = bitRangeConvert( (c1>> 5)&0x3f, 6, 8);
2573 colors[14] = bitRangeConvert( (c1>>11)&0x1f, 5, 8);
2574
2575 colors[ 4] = (2 * colors[0] + colors[12]) / 3;
2576 colors[ 5] = (2 * colors[1] + colors[13]) / 3;
2577 colors[ 6] = (2 * colors[2] + colors[14]) / 3;
2578
2579 colors[ 8] = (colors[0] + 2 * colors[12]) / 3;
2580 colors[ 9] = (colors[1] + 2 * colors[13]) / 3;
2581 colors[10] = (colors[2] + 2 * colors[14]) / 3;
2582 }
2583 else
2584 {
2585 colors[ 0] = 0;
2586 colors[ 1] = 0;
2587 colors[ 2] = 0;
2588
2589 colors[ 8] = bitRangeConvert( (c0>> 0)&0x1f, 5, 8);
2590 colors[ 9] = bitRangeConvert( (c0>> 5)&0x1f, 5, 8);
2591 colors[10] = bitRangeConvert( (c0>>10)&0x1f, 5, 8);
2592
2593 colors[12] = bitRangeConvert( (c1>> 0)&0x1f, 5, 8);
2594 colors[13] = bitRangeConvert( (c1>> 5)&0x3f, 6, 8);
2595 colors[14] = bitRangeConvert( (c1>>11)&0x1f, 5, 8);
2596
2597 colors[ 4] = colors[ 8] - colors[12] / 4;
2598 colors[ 5] = colors[ 9] - colors[13] / 4;
2599 colors[ 6] = colors[10] - colors[14] / 4;
2600 }
2601
2602 for (uint32_t ii = 0, next = 8*4; ii < 16*4; ii += 4, next += 2)
2603 {
2604 int32_t idx = ( (_src[next>>3] >> (next & 7) ) & 3) * 4;
2605 _dst[ii+0] = colors[idx+0];
2606 _dst[ii+1] = colors[idx+1];
2607 _dst[ii+2] = colors[idx+2];
2608 _dst[ii+3] = colors[idx+3];
2609 }
2610 }

Callers 1

imageDecodeToBgra8Function · 0.85

Calls 1

bitRangeConvertFunction · 0.85

Tested by

no test coverage detected