Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/particles/qquickmaskextruder.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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> | - | ||||||||||||
46 | QT_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 | - | |||||||||||||
64 | QQuickMaskExtruder::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:
| 14 | ||||||||||||
70 | - | |||||||||||||
71 | void QQuickMaskExtruder::setSource(QUrl arg) | - | ||||||||||||
72 | { | - | ||||||||||||
73 | if (m_source != arg) {
| 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:
| 14 | ||||||||||||
81 | } executed 14 times by 2 tests: end of block Executed by:
| 14 | ||||||||||||
82 | - | |||||||||||||
83 | void QQuickMaskExtruder::startMaskLoading() | - | ||||||||||||
84 | { | - | ||||||||||||
85 | m_pix.clear(this); | - | ||||||||||||
86 | if (m_source.isEmpty())
| 0-14 | ||||||||||||
87 | return; never executed: return; | 0 | ||||||||||||
88 | m_pix.load(qmlEngine(this), m_source); | - | ||||||||||||
89 | if (m_pix.isLoading())
| 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:
| 14 | ||||||||||||
93 | } | - | ||||||||||||
94 | - | |||||||||||||
95 | void QQuickMaskExtruder::finishMaskLoading() | - | ||||||||||||
96 | { | - | ||||||||||||
97 | if (m_pix.isError())
| 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:
| 14 | ||||||||||||
100 | - | |||||||||||||
101 | QPointF QQuickMaskExtruder::extrude(const QRectF &r) | - | ||||||||||||
102 | { | - | ||||||||||||
103 | ensureInitialized(r); | - | ||||||||||||
104 | if (!m_mask.count() || m_img.isNull())
| 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:
| 1216 | ||||||||||||
109 | } | - | ||||||||||||
110 | - | |||||||||||||
111 | bool 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())
| 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 | - | |||||||||||||
123 | void 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())
| 0-1214 | ||||||||||||
129 | return;//Same as before executed 1214 times by 1 test: return; Executed by:
| 1214 | ||||||||||||
130 | if (!m_pix.isReady())
| 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)
| 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) {
| 2-640 | ||||||||||||
149 | const uint *sl = (const uint *) m_img.constScanLine((y * sy) >> 16); | - | ||||||||||||
150 | for (int x=0; x<w; ++x) {
| 640-204800 | ||||||||||||
151 | if (sl[(x * sx) >> 16] & 0xff000000)
| 20402-184398 | ||||||||||||
152 | m_mask << QPointF(x, y); executed 20402 times by 1 test: m_mask << QPointF(x, y); Executed by:
| 20402 | ||||||||||||
153 | } executed 204800 times by 1 test: end of block Executed by:
| 204800 | ||||||||||||
154 | } executed 640 times by 1 test: end of block Executed by:
| 640 | ||||||||||||
155 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
156 | QT_END_NAMESPACE | - | ||||||||||||
157 | - | |||||||||||||
158 | #include "moc_qquickmaskextruder_p.cpp" | - | ||||||||||||
Source code | Switch to Preprocessed file |