OpenCoverage

qsgktxhandler.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/compressedtexture/qsgktxhandler.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2017 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQuick module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qsgktxhandler_p.h"-
41#include "qsgcompressedtexture_p.h"-
42#include <QOpenGLTexture>-
43#include <QtEndian>-
44-
45//#define KTX_DEBUG-
46-
47QT_BEGIN_NAMESPACE-
48-
49#define KTX_IDENTIFIER_LENGTH 12-
50static const char ktxIdentifier[KTX_IDENTIFIER_LENGTH] = { '\xAB', 'K', 'T', 'X', ' ', '1', '1', '\xBB', '\r', '\n', '\x1A', '\n' };-
51static const quint32 platformEndianIdentifier = 0x04030201;-
52static const quint32 inversePlatformEndianIdentifier = 0x01020304;-
53-
54struct KTXHeader {-
55 quint8 identifier[KTX_IDENTIFIER_LENGTH]; //Must match ktxIdentifier-
56 quint32 endianness; //Either platformEndianIdentifier or inversePlatformEndianIdentifier, other values not allowed.-
57 quint32 glType;-
58 quint32 glTypeSize;-
59 quint32 glFormat;-
60 quint32 glInternalFormat;-
61 quint32 glBaseInternalFormat;-
62 quint32 pixelWidth;-
63 quint32 pixelHeight;-
64 quint32 pixelDepth;-
65 quint32 numberOfArrayElements;-
66 quint32 numberOfFaces;-
67 quint32 numberOfMipmapLevels;-
68 quint32 bytesOfKeyValueData;-
69};-
70-
71static const int headerSize = sizeof(KTXHeader);-
72-
73// Currently unused, declared for future reference-
74struct KTXKeyValuePairItem {-
75 quint32 keyAndValueByteSize;-
76 /*-
77 quint8 keyAndValue[keyAndValueByteSize];-
78 quint8 valuePadding[3 - ((keyAndValueByteSize + 3) % 4)];-
79 */-
80};-
81-
82struct KTXMipmapLevel {-
83 quint32 imageSize;-
84 /*-
85 for each array_element in numberOfArrayElements*-
86 for each face in numberOfFaces-
87 for each z_slice in pixelDepth*-
88 for each row or row_of_blocks in pixelHeight*-
89 for each pixel or block_of_pixels in pixelWidth-
90 Byte data[format-specific-number-of-bytes]**-
91 end-
92 end-
93 end-
94 Byte cubePadding[0-3]-
95 end-
96 end-
97 quint8 mipPadding[3 - ((imageSize + 3) % 4)]-
98 */-
99};-
100-
101bool QSGKtxHandler::canRead(const QByteArray &suffix, const QByteArray &block)-
102{-
103 Q_UNUSED(suffix)-
104-
105 return (qstrncmp(block.constData(), ktxIdentifier, KTX_IDENTIFIER_LENGTH) == 0);
executed 712 times by 34 tests: return (qstrncmp(block.constData(), ktxIdentifier, 12) == 0);
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
  • ...
712
106}-
107-
108QQuickTextureFactory *QSGKtxHandler::read()-
109{-
110 if (!device())
!device()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickimage
0-2
111 return nullptr;
never executed: return nullptr;
0
112-
113 QByteArray buf = device()->readAll();-
114 if (buf.size() < headerSize || !canRead(QByteArray(), buf)) {
buf.size() < headerSizeDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickimage
!canRead(QByteArray(), buf)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickimage
0-2
115 qCDebug(QSG_LOG_TEXTUREIO, "Invalid KTX file %s", logName().constData());
never executed: QMessageLogger(__FILE__, 115, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Invalid KTX file %s", logName().constData());
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
116 return nullptr;
never executed: return nullptr;
0
117 }-
118-
119 const KTXHeader *header = reinterpret_cast<const KTXHeader *>(buf.constData());-
120 if (!checkHeader(*header)) {
!checkHeader(*header)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickimage
0-2
121 qCDebug(QSG_LOG_TEXTUREIO, "Unsupported KTX file format in %s", logName().constData());
never executed: QMessageLogger(__FILE__, 121, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Unsupported KTX file format in %s", logName().constData());
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
122 return nullptr;
never executed: return nullptr;
0
123 }-
124-
125 QSGCompressedTexture::DataPtr texData(QSGCompressedTexture::DataPtr::create());-
126-
127 texData->size = QSize(decode(header->pixelWidth), decode(header->pixelHeight));-
128 texData->format = decode(header->glInternalFormat);-
129 texData->hasAlpha = !QSGCompressedTexture::formatIsOpaque(texData->format);-
130-
131 // For now, ignore any additional mipmap levels-
132 int preambleSize = headerSize + decode(header->bytesOfKeyValueData);-
133 if (buf.size() >= preambleSize + int(sizeof(KTXMipmapLevel))) {
buf.size() >= ...XMipmapLevel))Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickimage
FALSEnever evaluated
0-2
134 texData->data = buf;-
135 texData->dataOffset = preambleSize + sizeof(quint32); // for the imageSize-
136 const KTXMipmapLevel *level = reinterpret_cast<const KTXMipmapLevel *>(buf.constData() + preambleSize);-
137 texData->dataLength = decode(level->imageSize);-
138 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_qquickimage
2
139-
140 if (!texData->isValid()) {
!texData->isValid()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickimage
0-2
141 qCDebug(QSG_LOG_TEXTUREIO, "Invalid values in header of KTX file %s", logName().constData());
never executed: QMessageLogger(__FILE__, 141, __PRETTY_FUNCTION__, QSG_LOG_TEXTUREIO().categoryName()).debug("Invalid values in header of KTX file %s", logName().constData());
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
142 return nullptr;
never executed: return nullptr;
0
143 }-
144-
145 texData->logName = logName();-
146#ifdef KTX_DEBUG-
147 qDebug() << "KTX file handler read" << texData.data();-
148#endif-
149-
150 return new QSGCompressedTextureFactory(texData);
executed 2 times by 1 test: return new QSGCompressedTextureFactory(texData);
Executed by:
  • tst_qquickimage
2
151}-
152-
153bool QSGKtxHandler::checkHeader(const KTXHeader &header)-
154{-
155 if (header.endianness != platformEndianIdentifier && header.endianness != inversePlatformEndianIdentifier)
header.endiann...dianIdentifierDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickimage
header.endiann...dianIdentifierDescription
TRUEnever evaluated
FALSEnever evaluated
0-2
156 return false;
never executed: return false;
0
157 inverseEndian = (header.endianness == inversePlatformEndianIdentifier);-
158#ifdef KTX_DEBUG-
159 QMetaEnum tfme = QMetaEnum::fromType<QOpenGLTexture::TextureFormat>();-
160 QMetaEnum ptme = QMetaEnum::fromType<QOpenGLTexture::PixelType>();-
161 qDebug("Header of %s:", logName().constData());-
162 qDebug(" glType: 0x%x (%s)", decode(header.glType), ptme.valueToKey(decode(header.glType)));-
163 qDebug(" glTypeSize: %u", decode(header.glTypeSize));-
164 qDebug(" glFormat: 0x%x (%s)", decode(header.glFormat), tfme.valueToKey(decode(header.glFormat)));-
165 qDebug(" glInternalFormat: 0x%x (%s)", decode(header.glInternalFormat), tfme.valueToKey(decode(header.glInternalFormat)));-
166 qDebug(" glBaseInternalFormat: 0x%x (%s)", decode(header.glBaseInternalFormat), tfme.valueToKey(decode(header.glBaseInternalFormat)));-
167 qDebug(" pixelWidth: %u", decode(header.pixelWidth));-
168 qDebug(" pixelHeight: %u", decode(header.pixelHeight));-
169 qDebug(" pixelDepth: %u", decode(header.pixelDepth));-
170 qDebug(" numberOfArrayElements: %u", decode(header.numberOfArrayElements));-
171 qDebug(" numberOfFaces: %u", decode(header.numberOfFaces));-
172 qDebug(" numberOfMipmapLevels: %u", decode(header.numberOfMipmapLevels));-
173 qDebug(" bytesOfKeyValueData: %u", decode(header.bytesOfKeyValueData));-
174#endif-
175 return ((decode(header.glType) == 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:
  • tst_qquickimage
2
176 (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:
  • tst_qquickimage
2
177 (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:
  • tst_qquickimage
2
178 (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:
  • tst_qquickimage
2
179}-
180-
181quint32 QSGKtxHandler::decode(quint32 val)-
182{-
183 return inverseEndian ? qbswap<quint32>(val) : val;
executed 18 times by 1 test: return inverseEndian ? qbswap<quint32>(val) : val;
Executed by:
  • tst_qquickimage
18
184}-
185-
186QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0