9 #include <ext/bc7enc_rdo/bc7decomp.h>
18 bool BC7TextureReader::read(
int width,
int height,
int bytesPerPixel,
const vector<uint8_t>& bc7Data,
ByteBuffer& textureByteBuffer) {
20 auto xBlocks =
static_cast<int>(Math::ceil(width / 4.0f));
21 auto yBlocks =
static_cast<int>(Math::ceil(height / 4.0f));
24 auto textureByteBufferBuffer = textureByteBuffer.
getBuffer();
27 for (
auto yBlock = 0; yBlock < yBlocks; yBlock++) {
28 for (
auto xBlock = 0; xBlock < xBlocks; xBlock++) {
30 array<bc7decomp::color_rgba, 4 * 4> rgbaBlockPixels { 0 };
31 bc7decomp::unpack_bc7(&bc7Data.data()[yBlock * xBlocks * 16 + xBlock * 16], rgbaBlockPixels.data());
33 auto blockPixelIdx = 0;
34 auto xBlockOffset = xBlock * 4;
35 auto yBlockOffset = yBlock * 4;
36 for (
int y = 0; y < 4; y++) {
37 for (
int x = 0; x < 4; x++) {
38 auto offset = (yBlockOffset + y) * width * bytesPerPixel + (xBlockOffset + x) * bytesPerPixel;
39 auto red = rgbaBlockPixels[blockPixelIdx].r;
40 auto green = rgbaBlockPixels[blockPixelIdx].g;
41 auto blue = rgbaBlockPixels[blockPixelIdx].b;
42 auto alpha = rgbaBlockPixels[blockPixelIdx].a;
44 textureByteBufferBuffer[offset + 0] = red;
45 textureByteBufferBuffer[offset + 1] = green;
46 textureByteBufferBuffer[offset + 2] = blue;
47 if (bytesPerPixel == 4) textureByteBufferBuffer[offset + 3] = alpha;
BC7 texture reader class.
const uint8_t * getBuffer() const
virtual int64_t getCapacity() const