Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/compressedtexture/qsgktxhandler.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | static const char ktxIdentifier[12] = { '\xAB', 'K', 'T', 'X', ' ', '1', '1', '\xBB', '\r', '\n', '\x1A', '\n' }; | - | ||||||||||||
8 | static const quint32 platformEndianIdentifier = 0x04030201; | - | ||||||||||||
9 | static const quint32 inversePlatformEndianIdentifier = 0x01020304; | - | ||||||||||||
10 | - | |||||||||||||
11 | struct KTXHeader { | - | ||||||||||||
12 | quint8 identifier[12]; | - | ||||||||||||
13 | quint32 endianness; | - | ||||||||||||
14 | quint32 glType; | - | ||||||||||||
15 | quint32 glTypeSize; | - | ||||||||||||
16 | quint32 glFormat; | - | ||||||||||||
17 | quint32 glInternalFormat; | - | ||||||||||||
18 | quint32 glBaseInternalFormat; | - | ||||||||||||
19 | quint32 pixelWidth; | - | ||||||||||||
20 | quint32 pixelHeight; | - | ||||||||||||
21 | quint32 pixelDepth; | - | ||||||||||||
22 | quint32 numberOfArrayElements; | - | ||||||||||||
23 | quint32 numberOfFaces; | - | ||||||||||||
24 | quint32 numberOfMipmapLevels; | - | ||||||||||||
25 | quint32 bytesOfKeyValueData; | - | ||||||||||||
26 | }; | - | ||||||||||||
27 | - | |||||||||||||
28 | static const int headerSize = sizeof(KTXHeader); | - | ||||||||||||
29 | - | |||||||||||||
30 | - | |||||||||||||
31 | struct KTXKeyValuePairItem { | - | ||||||||||||
32 | quint32 keyAndValueByteSize; | - | ||||||||||||
33 | - | |||||||||||||
34 | - | |||||||||||||
35 | - | |||||||||||||
36 | - | |||||||||||||
37 | }; | - | ||||||||||||
38 | - | |||||||||||||
39 | struct KTXMipmapLevel { | - | ||||||||||||
40 | quint32 imageSize; | - | ||||||||||||
41 | }; | - | ||||||||||||
42 | - | |||||||||||||
43 | bool QSGKtxHandler::canRead(const QByteArray &suffix, const QByteArray &block) | - | ||||||||||||
44 | { | - | ||||||||||||
45 | (void)suffix; | - | ||||||||||||
46 | - | |||||||||||||
47 | return executed 712 times by 34 tests: (qstrncmp(block.constData(), ktxIdentifier, 12) == 0);return (qstrncmp(block.constData(), ktxIdentifier, 12) == 0); Executed by:
executed 712 times by 34 tests: return (qstrncmp(block.constData(), ktxIdentifier, 12) == 0); Executed by:
| 712 | ||||||||||||
48 | } | - | ||||||||||||
49 | - | |||||||||||||
50 | QQuickTextureFactory *QSGKtxHandler::read() | - | ||||||||||||
51 | { | - | ||||||||||||
52 | if (!device()
| 0-2 | ||||||||||||
53 | return never executed: nullptr;return nullptr; never executed: return nullptr; | 0 | ||||||||||||
54 | - | |||||||||||||
55 | QByteArray buf = device()->readAll(); | - | ||||||||||||
56 | if (buf.size() < headerSize
| 0-2 | ||||||||||||
57 | for (bool qt_category_enabled = QSG_LOG_TEXTUREIO().isDebugEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 115, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Invalid KTX file %s", logName().constData()); | 0 | ||||||||||||
58 | return never executed: nullptr;return nullptr; never executed: return nullptr; | 0 | ||||||||||||
59 | } | - | ||||||||||||
60 | - | |||||||||||||
61 | const KTXHeader *header = reinterpret_cast<const KTXHeader *>(buf.constData()); | - | ||||||||||||
62 | if (!checkHeader(*header)
| 0-2 | ||||||||||||
63 | for (bool qt_category_enabled = QSG_LOG_TEXTUREIO().isDebugEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 121, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Unsupported KTX file format in %s", logName().constData()); | 0 | ||||||||||||
64 | return never executed: nullptr;return nullptr; never executed: return nullptr; | 0 | ||||||||||||
65 | } | - | ||||||||||||
66 | - | |||||||||||||
67 | QSGCompressedTexture::DataPtr texData(QSGCompressedTexture::DataPtr::create()); | - | ||||||||||||
68 | - | |||||||||||||
69 | texData->size = QSize(decode(header->pixelWidth), decode(header->pixelHeight)); | - | ||||||||||||
70 | texData->format = decode(header->glInternalFormat); | - | ||||||||||||
71 | texData->hasAlpha = !QSGCompressedTexture::formatIsOpaque(texData->format); | - | ||||||||||||
72 | - | |||||||||||||
73 | - | |||||||||||||
74 | int preambleSize = headerSize + decode(header->bytesOfKeyValueData); | - | ||||||||||||
75 | if (buf.size() >= preambleSize + int(sizeof(KTXMipmapLevel))
| 0-2 | ||||||||||||
76 | texData->data = buf; | - | ||||||||||||
77 | texData->dataOffset = preambleSize + sizeof(quint32); | - | ||||||||||||
78 | const KTXMipmapLevel *level = reinterpret_cast<const KTXMipmapLevel *>(buf.constData() + preambleSize); | - | ||||||||||||
79 | texData->dataLength = decode(level->imageSize); | - | ||||||||||||
80 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
81 | - | |||||||||||||
82 | if (!texData->isValid()
| 0-2 | ||||||||||||
83 | for (bool qt_category_enabled = QSG_LOG_TEXTUREIO().isDebugEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 141, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Invalid values in header of KTX file %s", logName().constData()); | 0 | ||||||||||||
84 | return never executed: nullptr;return nullptr; never executed: return nullptr; | 0 | ||||||||||||
85 | } | - | ||||||||||||
86 | - | |||||||||||||
87 | texData->logName = logName(); | - | ||||||||||||
88 | - | |||||||||||||
89 | - | |||||||||||||
90 | - | |||||||||||||
91 | - | |||||||||||||
92 | return executed 2 times by 1 test: new QSGCompressedTextureFactory(texData);return new QSGCompressedTextureFactory(texData); Executed by:
executed 2 times by 1 test: return new QSGCompressedTextureFactory(texData); Executed by:
| 2 | ||||||||||||
93 | } | - | ||||||||||||
94 | - | |||||||||||||
95 | bool QSGKtxHandler::checkHeader(const KTXHeader &header) | - | ||||||||||||
96 | { | - | ||||||||||||
97 | if (header.endianness != platformEndianIdentifier
| 0-2 | ||||||||||||
98 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
99 | inverseEndian = (header.endianness == inversePlatformEndianIdentifier); | - | ||||||||||||
100 | return executed 2 times by 1 test: ((decode(header.glType) == 0) &&return ((decode(header.glType) == 0) && (decode(header.glFormat) == 0) && (decode(header.pixelDepth) == 0) && (decode(header.numberOfFaces) == 1)); Executed by:
executed 2 times by 1 test: return ((decode(header.glType) == 0) && (decode(header.glFormat) == 0) && (decode(header.pixelDepth) == 0) && (decode(header.numberOfFaces) == 1)); Executed by:
| 2 | ||||||||||||
101 | (decode(header.glFormat) == 0) && executed 2 times by 1 test: return ((decode(header.glType) == 0) && (decode(header.glFormat) == 0) && (decode(header.pixelDepth) == 0) && (decode(header.numberOfFaces) == 1)); Executed by:
| 2 | ||||||||||||
102 | (decode(header.pixelDepth) == 0) && executed 2 times by 1 test: return ((decode(header.glType) == 0) && (decode(header.glFormat) == 0) && (decode(header.pixelDepth) == 0) && (decode(header.numberOfFaces) == 1)); Executed by:
| 2 | ||||||||||||
103 | (decode(header.numberOfFaces) == 1)); executed 2 times by 1 test: return ((decode(header.glType) == 0) && (decode(header.glFormat) == 0) && (decode(header.pixelDepth) == 0) && (decode(header.numberOfFaces) == 1)); Executed by:
| 2 | ||||||||||||
104 | } | - | ||||||||||||
105 | - | |||||||||||||
106 | quint32 QSGKtxHandler::decode(quint32 val) | - | ||||||||||||
107 | { | - | ||||||||||||
108 | return executed 18 times by 1 test: inverseEndian ? qbswap<quint32>(val) : val;return inverseEndian ? qbswap<quint32>(val) : val; Executed by:
executed 18 times by 1 test: return inverseEndian ? qbswap<quint32>(val) : val; Executed by:
| 18 | ||||||||||||
109 | } | - | ||||||||||||
110 | - | |||||||||||||
111 | - | |||||||||||||
Switch to Source code | Preprocessed file |