83 QByteArray fileData = device()->readAll();
84 if (fileData.size() <
int(
sizeof(AstcHeader)) || !canRead(QByteArray(), fileData)) {
85 qCDebug(lcQtGuiTextureIO,
"Not an ASTC file: %s", logName().constData());
88 res.setData(fileData);
92 int xSz =
int(header->xSize[0]) |
int(header->xSize[1]) << 8 |
int(header->xSize[2]) << 16;
93 int ySz =
int(header->ySize[0]) |
int(header->ySize[1]) << 8 |
int(header->ySize[2]) << 16;
94 int zSz =
int(header->zSize[0]) |
int(header->zSize[1]) << 8 |
int(header->zSize[2]) << 16;
96 quint32 glFmt = astcGLFormat(header->blockDimX, header->blockDimY);
98 if (!xSz || !ySz || !zSz || !glFmt || header->blockDimZ != 1) {
99 qCDebug(lcQtGuiTextureIO,
"Invalid ASTC header data in file %s", logName().constData());
103 res.setSize(QSize(xSz, ySz));
105 res.setGLInternalFormat(glFmt);
108 int xBlocks = (xSz + header->blockDimX - 1) / header->blockDimX;
109 int yBlocks = (ySz + header->blockDimY - 1) / header->blockDimY;
110 int zBlocks = (zSz + header->blockDimZ - 1) / header->blockDimZ;
113 bool oob = qMulOverflow(xBlocks, yBlocks, &byteCount)
114 || qMulOverflow(byteCount, zBlocks, &byteCount)
115 || qMulOverflow(byteCount, 16, &byteCount);
118 res.setDataOffset(
sizeof(AstcHeader));
121 res.setDataLength(byteCount);
123 if (oob || !res.isValid()) {
124 qCDebug(lcQtGuiTextureIO,
"Invalid ASTC file %s", logName().constData());
128 res.setLogName(logName());
131 qDebug() <<
"ASTC file handler read" << res << res.dataOffset() << res.dataLength();