| 55 | static_assert(Quality::Count == BX_COUNTOF(s_astcQuality) ); |
| 56 | |
| 57 | void imageEncodeFromRgba8(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, TextureFormat::Enum _format, Quality::Enum _quality, bx::Error* _err) |
| 58 | { |
| 59 | const uint8_t* src = (const uint8_t*)_src; |
| 60 | uint8_t* dst = (uint8_t*)_dst; |
| 61 | |
| 62 | const uint32_t srcPitch = _width*4; |
| 63 | const uint32_t srcSlice = _height*srcPitch; |
| 64 | const uint32_t dstBpp = getBitsPerPixel(_format); |
| 65 | const uint32_t dstPitch = _width*dstBpp/8; |
| 66 | const uint32_t dstSlice = _height*dstPitch; |
| 67 | |
| 68 | for (uint32_t zz = 0; zz < _depth && _err->isOk(); ++zz, src += srcSlice, dst += dstSlice) |
| 69 | { |
| 70 | switch (_format) |
| 71 | { |
| 72 | case TextureFormat::BC1: |
| 73 | case TextureFormat::BC2: |
| 74 | case TextureFormat::BC3: |
| 75 | case TextureFormat::BC4: |
| 76 | case TextureFormat::BC5: |
| 77 | squish::CompressImage(src, _width, _height, dst |
| 78 | , s_squishQuality[_quality] |
| 79 | | (_format == TextureFormat::BC2 ? squish::kDxt3 |
| 80 | : _format == TextureFormat::BC3 ? squish::kDxt5 |
| 81 | : _format == TextureFormat::BC4 ? squish::kBc4 |
| 82 | : _format == TextureFormat::BC5 ? squish::kBc5 |
| 83 | : squish::kDxt1) |
| 84 | ); |
| 85 | break; |
| 86 | |
| 87 | case TextureFormat::BC6H: |
| 88 | case TextureFormat::BC7: |
| 89 | BX_ERROR_SET(_err, BIMG_ERROR, "Unable to convert between input/output formats!"); |
| 90 | break; |
| 91 | |
| 92 | case TextureFormat::ETC1: |
| 93 | etc1_encode_image(src, _width, _height, 4, _width*4, dst); |
| 94 | break; |
| 95 | |
| 96 | case TextureFormat::ETC2: |
| 97 | { |
| 98 | const uint32_t blockWidth = (_width +3)/4; |
| 99 | const uint32_t blockHeight = (_height+3)/4; |
| 100 | uint64_t* dstBlock = (uint64_t*)dst; |
| 101 | for (uint32_t yy = 0; yy < blockHeight; ++yy) |
| 102 | { |
| 103 | for (uint32_t xx = 0; xx < blockWidth; ++xx) |
| 104 | { |
| 105 | uint8_t block[4*4*4]; |
| 106 | const uint8_t* ptr = &src[(yy*srcPitch+xx*4)*4]; |
| 107 | |
| 108 | for (uint32_t ii = 0; ii < 16; ++ii) |
| 109 | { // BGRx |
| 110 | bx::memCopy(&block[ii*4], &ptr[(ii%4)*srcPitch + (ii&~3)], 4); |
| 111 | bx::swap(block[ii*4+0], block[ii*4+2]); |
| 112 | } |
| 113 | |
| 114 | *dstBlock++ = ProcessRGB_ETC2(block); |
no test coverage detected