OpenCoverage

qsgpkmhandler.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/compressedtexture/qsgpkmhandler.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 "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//#define ETC_DEBUG-
51-
52QT_BEGIN_NAMESPACE-
53-
54static const int headerSize = 16;-
55-
56static unsigned int typeMap[5] = {-
57 QOpenGLTexture::RGB8_ETC1, // GL_ETC1_RGB8_OES,-
58 QOpenGLTexture::RGB8_ETC2, // GL_COMPRESSED_RGB8_ETC2,-
59 0, // unused (obsolete)-
60 QOpenGLTexture::RGBA8_ETC2_EAC, // GL_COMPRESSED_RGBA8_ETC2_EAC,-
61 QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2 // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2-
62};-
63-
64bool 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-
71QQuickTextureFactory *QSGPkmHandler::read()-
72{-
73 if (!device())
!device()Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qquickimage
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)) {
texData->data....) < headerSizeDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qquickimage
!canRead(QByte...texData->data)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qquickimage
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());
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
81 return nullptr;
never executed: return nullptr;
0
82 }-
83-
84 const char *rawData = texData->data.constData();-
85-
86 // ignore version (rawData + 4 & 5)-
87-
88 // texture type-
89 quint16 type = qFromBigEndian<quint16>(rawData + 6);-
90 if (type > sizeof(typeMap)/sizeof(typeMap[0])) {
type > sizeof(...of(typeMap[0])Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qquickimage
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());
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever 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 // texture size-
98 const int bpb = (texData->format == QOpenGLTexture::RGBA8_ETC2_EAC) ? 16 : 8;
(texData->form...GBA8_ETC2_EAC)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qquickimage
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()) {
!texData->isValid()Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qquickimage
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());
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever 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);
Executed by:
  • tst_qquickimage
8
116}-
117-
118QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0