Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qsgpkmhandler_p.h" | - |
41 | #include "qsgcompressedtexture_p.h" | - |
42 | | - |
43 | #include <QFile> | - |
44 | #include <QDebug> | - |
45 | #include <qendian.h> | - |
46 | #include <qopenglfunctions.h> | - |
47 | #include <qqmlfile.h> | - |
48 | #include <QOpenGLTexture> | - |
49 | | - |
50 | | - |
51 | | - |
52 | QT_BEGIN_NAMESPACE | - |
53 | | - |
54 | static const int headerSize = 16; | - |
55 | | - |
56 | static unsigned int typeMap[5] = { | - |
57 | QOpenGLTexture::RGB8_ETC1, | - |
58 | QOpenGLTexture::RGB8_ETC2, | - |
59 | 0, | - |
60 | QOpenGLTexture::RGBA8_ETC2_EAC, | - |
61 | QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2 | - |
62 | }; | - |
63 | | - |
64 | bool QSGPkmHandler::canRead(const QByteArray &suffix, const QByteArray &block) | - |
65 | { | - |
66 | Q_UNUSED(suffix) | - |
67 | | - |
68 | return block.startsWith("PKM ");executed 726 times by 34 tests: return block.startsWith("PKM "); Executed by:- tst_examples
- tst_qquickage
- tst_qquickangleddirection
- tst_qquickanimatedsprite
- tst_qquickborderimage
- tst_qquickcumulativedirection
- tst_qquickcustomaffector
- tst_qquickcustomparticle
- tst_qquickellipseextruder
- tst_qquickfriction
- tst_qquickgravity
- tst_qquickgroupgoal
- tst_qquickimage
- tst_qquickimageparticle
- tst_qquickitemparticle
- tst_qquicklineextruder
- tst_qquickmaskextruder
- tst_qquickparticlegroup
- tst_qquickparticlesystem
- tst_qquickpixmapcache
- tst_qquickpointattractor
- tst_qquickpointdirection
- tst_qquickrectangleextruder
- tst_qquickshadereffect
- tst_qquickspritegoal
- ...
| 726 |
69 | } | - |
70 | | - |
71 | QQuickTextureFactory *QSGPkmHandler::read() | - |
72 | { | - |
73 | if (!device())TRUE | never evaluated | FALSE | evaluated 8 times by 1 test |
| 0-8 |
74 | return nullptr; never executed: return nullptr; | 0 |
75 | | - |
76 | QSGCompressedTexture::DataPtr texData(QSGCompressedTexture::DataPtr::create()); | - |
77 | | - |
78 | texData->data = device()->readAll(); | - |
79 | if (texData->data.size() < headerSize || !canRead(QByteArray(), texData->data)) {TRUE | never evaluated | FALSE | evaluated 8 times by 1 test |
TRUE | never evaluated | FALSE | evaluated 8 times by 1 test |
| 0-8 |
80 | qCDebug(QSG_LOG_TEXTUREIO, "Invalid PKM file %s", logName().constData()); never executed: QMessageLogger(__FILE__, 80, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Invalid PKM file %s", logName().constData()); TRUE | never evaluated | FALSE | never evaluated |
| 0 |
81 | return nullptr; never executed: return nullptr; | 0 |
82 | } | - |
83 | | - |
84 | const char *rawData = texData->data.constData(); | - |
85 | | - |
86 | | - |
87 | | - |
88 | | - |
89 | quint16 type = qFromBigEndian<quint16>(rawData + 6); | - |
90 | if (type > sizeof(typeMap)/sizeof(typeMap[0])) {TRUE | never evaluated | FALSE | evaluated 8 times by 1 test |
| 0-8 |
91 | qCDebug(QSG_LOG_TEXTUREIO, "Unknown compression format in PKM file %s", logName().constData()); never executed: QMessageLogger(__FILE__, 91, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Unknown compression format in PKM file %s", logName().constData()); TRUE | never evaluated | FALSE | never evaluated |
| 0 |
92 | return nullptr; never executed: return nullptr; | 0 |
93 | } | - |
94 | texData->format = typeMap[type]; | - |
95 | texData->hasAlpha = !QSGCompressedTexture::formatIsOpaque(texData->format); | - |
96 | | - |
97 | | - |
98 | const int bpb = (texData->format == QOpenGLTexture::RGBA8_ETC2_EAC) ? 16 : 8;TRUE | never evaluated | FALSE | evaluated 8 times by 1 test |
| 0-8 |
99 | QSize paddedSize(qFromBigEndian<quint16>(rawData + 8), qFromBigEndian<quint16>(rawData + 10)); | - |
100 | texData->dataLength = (paddedSize.width() / 4) * (paddedSize.height() / 4) * bpb; | - |
101 | QSize texSize(qFromBigEndian<quint16>(rawData + 12), qFromBigEndian<quint16>(rawData + 14)); | - |
102 | texData->size = texSize; | - |
103 | | - |
104 | texData->dataOffset = headerSize; | - |
105 | | - |
106 | if (!texData->isValid()) {TRUE | never evaluated | FALSE | evaluated 8 times by 1 test |
| 0-8 |
107 | qCDebug(QSG_LOG_TEXTUREIO, "Invalid values in header of PKM file %s", logName().constData()); never executed: QMessageLogger(__FILE__, 107, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Invalid values in header of PKM file %s", logName().constData()); TRUE | never evaluated | FALSE | never evaluated |
| 0 |
108 | return nullptr; never executed: return nullptr; | 0 |
109 | } | - |
110 | | - |
111 | texData->logName = logName(); | - |
112 | #ifdef ETC_DEBUG | - |
113 | qDebug() << "PKM file handler read" << texData.data(); | - |
114 | #endif | - |
115 | return new QSGCompressedTextureFactory(texData);executed 8 times by 1 test: return new QSGCompressedTextureFactory(texData); | 8 |
116 | } | - |
117 | | - |
118 | QT_END_NAMESPACE | - |
| | |