OpenCoverage

qquickmaskextruder.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/particles/qquickmaskextruder.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 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 "qquickmaskextruder_p.h"-
41#include <QtQml/qqml.h>-
42#include <QtQml/qqmlinfo.h>-
43#include <QImage>-
44#include <QDebug>-
45#include <QRandomGenerator>-
46QT_BEGIN_NAMESPACE-
47/*!-
48 \qmltype MaskShape-
49 \instantiates QQuickMaskExtruder-
50 \inqmlmodule QtQuick.Particles-
51 \inherits Shape-
52 \brief For representing an image as a shape to affectors and emitters.-
53 \ingroup qtquick-particles-
54-
55*/-
56/*!-
57 \qmlproperty url QtQuick.Particles::MaskShape::source-
58-
59 The image to use as the mask. Areas with non-zero opacity-
60 will be considered inside the shape.-
61*/-
62-
63-
64QQuickMaskExtruder::QQuickMaskExtruder(QObject *parent) :-
65 QQuickParticleExtruder(parent)-
66 , m_lastWidth(-1)-
67 , m_lastHeight(-1)-
68{-
69}
executed 14 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickmaskextruder
14
70-
71void QQuickMaskExtruder::setSource(QUrl arg)-
72{-
73 if (m_source != arg) {
m_source != argDescription
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickmaskextruder
FALSEnever evaluated
0-14
74 m_source = arg;-
75-
76 m_lastHeight = -1;//Trigger reset-
77 m_lastWidth = -1;-
78 emit sourceChanged(arg);-
79 startMaskLoading();-
80 }
executed 14 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickmaskextruder
14
81}
executed 14 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickmaskextruder
14
82-
83void QQuickMaskExtruder::startMaskLoading()-
84{-
85 m_pix.clear(this);-
86 if (m_source.isEmpty())
m_source.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 14 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickmaskextruder
0-14
87 return;
never executed: return;
0
88 m_pix.load(qmlEngine(this), m_source);-
89 if (m_pix.isLoading())
m_pix.isLoading()Description
TRUEnever evaluated
FALSEevaluated 14 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickmaskextruder
0-14
90 m_pix.connectFinished(this, SLOT(finishMaskLoading()));
never executed: m_pix.connectFinished(this, qFlagLocation("1""finishMaskLoading()" "\0" __FILE__ ":" "90"));
0
91 else-
92 finishMaskLoading();
executed 14 times by 2 tests: finishMaskLoading();
Executed by:
  • tst_examples
  • tst_qquickmaskextruder
14
93}-
94-
95void QQuickMaskExtruder::finishMaskLoading()-
96{-
97 if (m_pix.isError())
m_pix.isError()Description
TRUEnever evaluated
FALSEevaluated 14 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickmaskextruder
0-14
98 qmlWarning(this) << m_pix.error();
never executed: qmlWarning(this) << m_pix.error();
0
99}
executed 14 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickmaskextruder
14
100-
101QPointF QQuickMaskExtruder::extrude(const QRectF &r)-
102{-
103 ensureInitialized(r);-
104 if (!m_mask.count() || m_img.isNull())
!m_mask.count()Description
TRUEnever evaluated
FALSEevaluated 1216 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
m_img.isNull()Description
TRUEnever evaluated
FALSEevaluated 1216 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
0-1216
105 return r.topLeft();
never executed: return r.topLeft();
0
106 const QPointF p = m_mask[QRandomGenerator::global()->bounded(m_mask.count())];-
107 //### Should random sub-pixel positioning be added?-
108 return p + r.topLeft();
executed 1216 times by 1 test: return p + r.topLeft();
Executed by:
  • tst_qquickmaskextruder
1216
109}-
110-
111bool QQuickMaskExtruder::contains(const QRectF &bounds, const QPointF &point)-
112{-
113 ensureInitialized(bounds);//###Current usage patterns WILL lead to different bounds/r calls. Separate list?-
114 if (m_img.isNull())
m_img.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
115 return false;
never executed: return false;
0
116-
117 QPointF pt = point - bounds.topLeft();-
118 QPoint p(pt.x() * m_img.width() / bounds.width(),-
119 pt.y() * m_img.height() / bounds.height());-
120 return m_img.rect().contains(p) && (m_img.pixel(p) & 0xff000000);
never executed: return m_img.rect().contains(p) && (m_img.pixel(p) & 0xff000000);
0
121}-
122-
123void QQuickMaskExtruder::ensureInitialized(const QRectF &rf)-
124{-
125 // Convert to integer coords to avoid comparing floats and ints which would-
126 // often result in rounding errors.-
127 QRect r = rf.toRect();-
128 if (m_lastWidth == r.width() && m_lastHeight == r.height())
m_lastWidth == r.width()Description
TRUEevaluated 1214 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
m_lastHeight == r.height()Description
TRUEevaluated 1214 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
FALSEnever evaluated
0-1214
129 return;//Same as before
executed 1214 times by 1 test: return;
Executed by:
  • tst_qquickmaskextruder
1214
130 if (!m_pix.isReady())
!m_pix.isReady()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
0-2
131 return;
never executed: return;
0
132 m_lastWidth = r.width();-
133 m_lastHeight = r.height();-
134-
135 m_mask.clear();-
136-
137 m_img = m_pix.image();-
138 // Image will in all likelyhood be in this format already, so-
139 // no extra memory or conversion takes place-
140 if (m_img.format() != QImage::Format_ARGB32 && m_img.format() != QImage::Format_ARGB32_Premultiplied)
m_img.format()...:Format_ARGB32Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
FALSEnever evaluated
m_img.format()..._PremultipliedDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
0-2
141 m_img = m_img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
never executed: m_img = m_img.convertToFormat(QImage::Format_ARGB32_Premultiplied);
0
142-
143 // resample on the fly using 16-bit-
144 int sx = (m_img.width() << 16) / r.width();-
145 int sy = (m_img.height() << 16) / r.height();-
146 int w = r.width();-
147 int h = r.height();-
148 for (int y=0; y<h; ++y) {
y<hDescription
TRUEevaluated 640 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
2-640
149 const uint *sl = (const uint *) m_img.constScanLine((y * sy) >> 16);-
150 for (int x=0; x<w; ++x) {
x<wDescription
TRUEevaluated 204800 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
FALSEevaluated 640 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
640-204800
151 if (sl[(x * sx) >> 16] & 0xff000000)
sl[(x * sx) >>...] & 0xff000000Description
TRUEevaluated 20402 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
FALSEevaluated 184398 times by 1 test
Evaluated by:
  • tst_qquickmaskextruder
20402-184398
152 m_mask << QPointF(x, y);
executed 20402 times by 1 test: m_mask << QPointF(x, y);
Executed by:
  • tst_qquickmaskextruder
20402
153 }
executed 204800 times by 1 test: end of block
Executed by:
  • tst_qquickmaskextruder
204800
154 }
executed 640 times by 1 test: end of block
Executed by:
  • tst_qquickmaskextruder
640
155}
executed 2 times by 1 test: end of block
Executed by:
  • tst_qquickmaskextruder
2
156QT_END_NAMESPACE-
157-
158#include "moc_qquickmaskextruder_p.cpp"-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0